[英]Android crop camera image
I'm building a camera app similar to barcode scanner shown in picture. 我正在构建类似于图片中所示的条形码扫描仪的相机应用程序。 I need to use both
Camera
and android.hardware.camera2
API to support android API >= 19. 我需要同时使用
Camera
和android.hardware.camera2
API来支持android API> = 19。
The main idea is to have camera preview on the whole screen, but save only part that isn't darkened(or take picture of area that isn't darkened). 主要思想是在整个屏幕上预览相机,但只保存未变暗的部分(或拍摄未变暗的区域的照片)。 I've already done some research and figured out that it's impossible to take only part of the picture through
Camera
and android.hardware.camera2
APIs(but I'm not 100% sure). 我已经做过一些研究,发现无法通过
Camera
和android.hardware.camera2
API仅仅拍摄部分照片(但我不确定100%)。 So I think I need to make some manipulations over the byte array(compressed into JPEG) which I receive as a result of camera capture. 因此,我认为我需要对由于摄像机捕获而收到的字节数组(压缩为JPEG)进行一些操作。
I tried to use BitmapRegionDecoder in this way: 我试图以这种方式使用BitmapRegionDecoder:
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(bytes, 0, bytes.length, false);
Bitmap bitmap = decoder.decodeRegion(new Rect(500, 500, 1500, 1500), null);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);
Where bytes
is JPEG compressed result of camera capture. 其中
bytes
是摄像机捕获的JPEG压缩结果。 But this approach changes the orientation of the image and doesn't crop region defined by Rect
(actually crops another part of the image) 但是这种方法会改变图像的方向,并且不会裁剪
Rect
定义的区域(实际上会裁剪图像的另一部分)
I would appreciate any suggestions and hints on how to achieve desired behavior. 我将不胜感激有关如何实现所需行为的任何建议和提示。
It has been a while, but people still interested in this question. 已经有一段时间了,但是人们仍然对这个问题感兴趣。 That's why I'm sharing how I resolved this problem.
这就是为什么我分享解决问题的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.