Yes, you can overlay SurfaceView with two translucent rectangles to cut a square.
You must calculate the expected crop effect on the captured welcome image. For example. if your camera supports an image size of 4368x2912, you need to crop (mLeft = 728, mTop = 0, mWidth = 2912, mHeight = 2912).
To apply custom cropping to Jpeg byte[] obtained from onPictureTaken () , you have two options: simple or efficient.
A simple way is to decode Jpeg data for a bitmap,
@Override public void onPictureTaken(final byte[] data, Camera camera) { Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length); picture = Bitmap.createBitmap(picture, mLeft, mTop, mWidth, mHeight); picture.compress(Bitmap.CompressFormat.JPEG, 85, mFileOutputStream); }
The disadvantages are that it can be slow and requires huge memory (maybe 60 megabytes for a camera with a resolution of 12 megapixels).
A smart approach is to use the Jpeg Lossless transform (see, for example, http://mediachest.sourceforge.net/mediautil/ ), using less than 10 megabytes. Note that this imposes some limitations, for example. in the example of the 12 megapixel camera above you might need mLeft = 720 because 728 is not divisible by 16.
Alex cohn
source share