2

I need to compress images before sending the images to the server via Android app. The images taken via camera are very large and they need to be compressed first. When a image is taken from Camera, there are some properties associated with the image like device model, aperture, location, etc.

I'm trying to compress the image, but during compression, those properties of the images are lost. Please help if there is any missing line of code or any library to compress the images without losing those properties.

  private void compressImageAndAddToArrayList(Uri imageURI) {
    Bitmap bm = null;
    try
    {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 2;
        // bm = Media.getBitmap(mContext.getContentResolver(), imageLoc);
        bm = BitmapFactory.decodeStream(mContext.getContentResolver().openInputStream(imageURI), null, options);

        File folder = new File(Environment.getExternalStorageDirectory() + File.separator + "VDMS" + File.separator + "Camera");
        folder.mkdirs();
        String now = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()).toString();
        String fileName = caseID +  "_" + now + ".jpg";
        File imageFile = new File(folder + File.separator + fileName);

        FileOutputStream out = new FileOutputStream(imageFile);
        bm.compress(Bitmap.CompressFormat.JPEG, 64, out); // quality ranges from 0-100
        bm.recycle();

        addDocumentToArrayList(String.valueOf(1), Uri.fromFile(imageFile));
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
Tejas Pandya
  • 3,987
  • 1
  • 26
  • 51
Ajay Taneja
  • 81
  • 1
  • 4
  • https://stackoverflow.com/questions/28424942/decrease-image-size-without-losing-its-quality-in-android – Athira Apr 19 '19 at 04:22

0 Answers0