Question

Currently, doing this only stores it into the gallery. I have no idea how to save the cropped photo into my own folder.

My Question is:

How can i save the file in to my local folder?

case CROP_FROM_CAMERA:          
            Bundle extras = data.getExtras();

            Bitmap photo = null;

            if (extras != null) {               
                photo = extras.getParcelable("data");

                mImageView.setImageBitmap(photo);
            }

            // Create new folder inside Palm Detect directory
            File mediaStorageDir2 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "Palm Detect",
                    "Cropped Image");


            // Create the storage directory if it does not exist
            if (!mediaStorageDir2.exists()) {                       
                if (!mediaStorageDir2.mkdirs()) {
                    Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
                            + "Cropped Image" + " directory");
                }
            }
            // Store cropped photo into gallery
            Images.Media.insertImage(getContentResolver(), photo, "Img_" + String.valueOf(System.currentTimeMillis()), "");




            break;
Was it helpful?

Solution

You need to add a local file by doing this

 try {

  mediaStorageDir2.createNewFile();

  FileOutputStream ostream = new FileOutputStream(mediaStorageDir2);
  photo.compress(CompressFormat.PNG, 10, ostream);
  ostream.flush();
  ostream.close();

  System.gc();

  } catch (Exception e) {
    e.printStackTrace();
}

Edit : Also you need to add permission to AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top