Possible Duplicate:
How to crop the parsed image in android?
I have an image in my res/drawable folder and I would like to crop (i.e. slice out some part of the image) the image when loading it into an ImageView. However I am unsure how to do this, any suggestions?
After you take the screenshot, you'll see a preview of the image in the bottom-left corner. From here you can tap “Edit.” This will take you to a basic photo editing screen. First, you can grab the corners to crop the screenshot.
From Bitmap.createBitmap: "Returns an immutable bitmap from the specified subset of the source bitmap. The new bitmap may be the same object as source, or a copy may have been made. It is initialized with the same density as the original bitmap."
Pass it a bitmap, and define the rectangle from which the new bitmap will be created.
// Take 10 pixels off the bottom of a Bitmap Bitmap croppedBmp = Bitmap.createBitmap(originalBmp, 0, 0, originalBmp.getWidth(), originalBmp.getHeight()-10);
The Android Contact manager EditContactActivity uses Intent("com.android.camera.action.CROP")
This is a sample code:
Intent intent = new Intent("com.android.camera.action.CROP"); // this will open all images in the Galery intent.setDataAndType(photoUri, "image/*"); intent.putExtra("crop", "true"); // this defines the aspect ration intent.putExtra("aspectX", aspectY); intent.putExtra("aspectY", aspectX); // this defines the output bitmap size intent.putExtra("outputX", sizeX); intent.putExtra("outputY", xizeY); // true to return a Bitmap, false to directly save the cropped iamge intent.putExtra("return-data", false); //save output image in uri intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With