Felipe Caldas
Felipe Caldas

Reputation: 2503

When taking picture with camera and sending to server-side, losing picture quality

I have been struggling with this issue for some days now and I really don't know what is the problem. My CameraView class has the following code:

Camera.PictureCallback photoCallback = new Camera.PictureCallback() {
    public void onPictureTaken(byte[] imageData, Camera camera) {
        Intent mIntent = new Intent();  
        mIntent.putExtra(GeneralCodes.CREATE_NEW_ACCOUNT_PROFILE_PICTURE, imageData);
        setResult(Activity.RESULT_OK, mIntent);
        finish();
    }
};

And then, my Activity that receives this result:

ImageView i = (ImageView) findViewById(R.id.createAccounProfileImage);
Bitmap yourSelectedImage = FileUtilities.createBitmapBasedOnByteImage(data.getByteArrayExtra(GeneralCodes.CREATE_NEW_ACCOUNT_PROFILE_PICTURE), getResources().getDisplayMetrics().density);

finalImage=yourSelectedImage;
            i.setImageBitmap(BitmapUtils.getRoundedCornerBitmap(finalImage, Math.min(finalImage.getWidth(), finalImage.getHeight()), true));        

The only thing the method FileUtilities.createBitmapBasedOnByteImage is really doing is just a BitmapFactory.decodeByteArray() call.

Then, my next step is sending this Bitmap to my server:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if(finalImage!=null)finalImage.compress(Bitmap.CompressFormat.JPEG, 0, baos);
    byte[] data = baos.toByteArray();

    pairs.add(new BasicNameValuePair("PROFILE_PIC_DATA", Base64.encodeToString(data, Base64.DEFAULT)));     

The information is sent to my server and image is persisted in the CLOB. When my next acticity retrieves this data:

bitmap = BitmapFactory.decodeStream(createInputStream(Base64.decode(obj.getString("photo_image"), Base64.DEFAULT)));

The quality is completely messed up. Like it was taken by a 0.3mpx camera. I am using Samsung Galaxy Nexus, so I believe that my screen is contributing to make it worse. The images have around 2.7kb size in the CLOB... so I am guessing data is being lost when sending to my server... Am not really sure.

Anyone ever seen this?

THanks, Felipe

Upvotes: 0

Views: 886

Answers (1)

kabuko
kabuko

Reputation: 36302

You're setting image quality to 0 when compressing. Instead set it to something bigger. See the docs. Something like:

if(finalImage!=null)finalImage.compress(Bitmap.CompressFormat.JPEG, 80, baos);

Upvotes: 2

Related Questions