Do this in your code (bearing in mind that it will not work on all phones like HTC because they use their own gallery / camera.
File f = new File(Environment.getExternalStorageDirectory(), "/temporary_holder.png"); f.createNewFile(); Intent intent = new Intent("com.android.camera.action.CROP"); intent.setClassName("com.android.gallery", "com.android.camera.CropImage"); intent.setType("image/*"); intent.setData(ImageToSetUri); // Local URI of your image intent.putExtra("crop", true); intent.putExtra("outputX", width); // width/height of your image intent.putExtra("outputY", height); intent.putExtra("aspectX", width); intent.putExtra("aspectY", height); intent.putExtra("scale", true); intent.putExtra("noFaceDetection", true); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name()); startActivityForResult(intent, 1);
then do this to get the image as a bitmap or nonetheless want
public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) if (data != null) { Bitmap selectedImage = BitmapFactory.decodeFile(f); } }
source share