Square image using custom camera

I open the camera using viewview and custom view. using this, I can successfully click the image using one of the sizes from getSupportedPictureSizes (). But I want pictures in a square shape. Right now I'm cropping it after clicking on the picture. In android, it is possible to show a bright vivid image and a dark overlay with the rest of the camera preview, and when clicked, only viewing inside the square opens. this is possible on the iPhone. but donโ€™t know how to do it in Android. Any help would be greatly appreciated.

+7
android customization camera
source share
1 answer

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.

+1
source share

All Articles