Question

I am opening camera using surfaceview and custom view. using this i am successfully able to click picture using one of sizes from getSupportedPictureSizes(). But i want pictures in square form. Right now i am cropping it after clicking picture. Is is possible in android to show square image bright and a dark overlay on remaining camera preview, and on clicking, only preview inside square gets clicked. this is possile in iPhone. but dont know how to do it in android. Any help will be highly appreciated.

No correct solution

OTHER TIPS

Yes, you can overlay a SurfaceView with 2 semitransparent rectangles to cut out the square.

You should calculate the expected crop effect on the captured hi-res image. E.g. if your camera supports picture size of 4368x2912, you will need to crop (mLeft=728, mTop=0, mWidth=2912, mHeight=2912).

To apply the custom crop to the Jpeg byte[] received from onPictureTaken(), you have two options: easy or efficient.

The easy way is to decode the Jpeg data to 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 drawbacks are that it may be slow and require huge memory (maybe 60 MBytes for 12 MPixel camera).

The "smart" approach is to use Jpeg Lossless transformation (see for example http://mediachest.sourceforge.net/mediautil/), using less than 10 MBytes. Note that this imposes some restrictions, e.g. in the example of 12 MPixel camera above, you may need mLeft=720, because 728 is not dividable by 16.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top