Some androids loading scrambled images

First, I use this code to save a photo on an Android SD card:

PictureCallback jpegCallback = new PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {

    FileOutputStream outStream = null;

    currentFilename = String.format("%d", System.currentTimeMillis());              
    outStream = new FileOutputStream("/sdcard/" + currentFilename + ".jpg");                    
    outStream.write(data);
    outStream.close();

    }
};

Then I use this code to upload photos on Android devices:

public void uploadPhoto() {

        try {

            // Create HttpPost
            HttpPost post = new HttpPost("http://www.example.com/upload.php");
            HttpClient client = new DefaultHttpClient();
            client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );

            // Add the Picture as "userfile"
            entity.addPart( "userfile", new FileBody( 
                new File( "/sdcard/", currentFilename + ".jpg" ),
                "image/jpeg")
            );


            // Send the data to the server
            post.setEntity( entity );
            client.execute( post );


        } catch (Exception e) {
            // catch
        } finally {
            // finally
        }

}

This works on my LG Optimus V running Android 2.2.2 and Droid X with Android 2.3.4

However, a user who has an HTC Evo running 2.3.4 (the same as my Droid X) experiences that all downloaded photos are scrambled when they are saved on her phone (and when they get to the server). The image looks like an array of jagged colored lines.

Any ideas on what might be happening here and what can be done to fix the problem?

Update:

, jpg SD-, , 3,5 - 4,0 , ... .

+5
3

. , .

:

Parameters params = camera.getParameters();
List<Camera.Size> sizes = params.getSupportedPictureSizes();

, , :

List<Size> sizes = params.getSupportedPictureSizes();
Size theBiggest=null;
int maxWidth = 0;
for (Size s : sizes) {
    if (s.width > maxWidth) {
        maxWidth = s.width;
        theBiggest = s;
    }
}

params.setPictureSize(theBiggest.width, theBiggest.height);
camera.setParameters(params);
+4

JPEG . , data Bitmap

currentFilename = String.format("%d", System.currentTimeMillis());              
outStream = new FileOutputStream("/sdcard/" + currentFilename + ".jpg");   
data.compress(Bitmap.CompressFormat.JPEG, 90, outStream );    
outStream.close();

compress api.. , 80, 80%.

.

0

Images must be saved in the sdcard to achieve full (uncompressed) size. Easy steps

  • capture image
  • save captured image to sdcard
  • load saved image from sdcard
  • convert it to an array of bytes and add as ByteArrayBody, or as you can skip step 3 and create a file body with a cached file.

Note: I am currently removed from my computer. I will write a detailed answer if there is no detailed message. Good luck.

0
source

All Articles