简体   繁体   中英

Cropping the Android camera

I'm developing an Android app that uses ZBar as a QR code library, and things are going sweet. Now, however, I'm building the interface for the app, and it requires that I show only a certain portion of the camera's feed at the bottom of the screen, something like this:

在此输入图像描述

The camera view below should be full-sized, ie a cropped view and not a resized one. However setting the width and height of the FrameLayout has caused it to resize and squash the entire image into the tiny frame.

Is there a way to crop it? I know I could probably place an overlay over the original image, but how does one create a transparent square in the middle to display what I need?Besides, the QR reader would catch anything the camera captures, so if the user brought the QR code in front of the camera and it captured it "off screen" (by the part that's actually covered by the overlay), it would be extremely confusing.

So I guess what I'm saying is, I can't use an overlay to "crop" the picture. Is there any other way to do it?

As far my knowledge one cannot crop camera view but what you can do is re-size the frame and then capture the image.

Still i would suggest to refer this post

The first thought that comes to mind is to put your CameraPreview in a view inside a FrameLayout . Then add more views on top of the CameraPreview view to hide the parts that you do not want to be visible.

Or Perhaps just one view super-imposing the camera preview view with a PNG which covers everything with "cropped" area set as transparent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM