0

I am trying to develop an app with a camera. I have already successfully saved the image in the SD card, but the image will be sent to a server, so I need the image to be of a smaller size. The size that I am getting right now is 2.3 MB. Is there a way that I could make the image smaller?

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

        File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
        if (pictureFile == null){
            return;
        }

        try {
            FileOutputStream fos = new FileOutputStream(pictureFile);
            fos.write(data);
            fos.close();
        } catch (FileNotFoundException e) {
            Log.d(TAG, "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d(TAG, "Error accessing file: " + e.getMessage());
        }
        camera.startPreview();
    }
};
lostsheep
  • 39
  • 1
  • 1
  • 6

2 Answers2

0

You can compress your bitmap image(if it is stored in Bitmap) using this

preview_bitmap.compress(CompressFormat.PNG, 90, out);

Maverick
  • 3,053
  • 6
  • 24
  • 30
0

You have two options:

  1. Resize the image. Best results are achieved, by reducing resolution by a factor of 2. See this for an example: https://stackoverflow.com/a/823966/248432

  2. Compress the image further (as Ravi Kumar already answered).

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154