如何在框架后面显示预览相机并拍摄包含框架的照片 [英] How to display preview camera behind a frame and take picture include frame
问题描述
我正在尝试使用相机API在android中构建相机应用。
I'm trying build a camera app in android using camera API.
我按照说明进行操作: https://examples.javacodegeeks.com/android/core/hardware/camera-hardware/android-camera- example / ,我已经构建了一个摄像头应用程序
I follow the instructions: https://examples.javacodegeeks.com/android/core/hardware/camera-hardware/android-camera-example/ and I have built one camera app
现在,我需要在框架内显示预览摄像头并拍照以包含框架
Now i need to display preview camera inside a frame and take picture include the frame
请参见以下两张图片:
资源文件夹中的框架: https://i.stack.imgur.com/AaNIQ.png
Frame in resource folder : https://i.stack.imgur.com/AaNIQ.png
照片我想实现: https://i.stack.imgur.com/UWXcq.jpg
任何人都可以给我建议,或者可能的话给我一个简单的例子?
Anyone can give me suggestions or if possible give me a simple example?
我在此搜索过但没有得到正确的电子
I searched about this but didn't get proper example.
非常感谢。
推荐答案
一半答案可以在这里找到: https://stackoverflow.com/a/47240902/192373
Half of the answer can be found here: https://stackoverflow.com/a/47240902/192373.
至于为全分辨率图像捕获保留相同的布局,首先请确保同步预览和图片大小。这并不意味着它们必须相同,但是纵横比应该相同。当长宽比更改以捕获照片时,某些设备会产生怪异的效果。
As for keeping the same layout for full-res picture capture, first of all make sure that you keep preview- and picture- sizes in sync. This does not mean that they must be the same, but the aspect ratios should. Some devices have weird effects when the aspect ratio changes to capture a photo.
下一步,您照常捕获jpeg,将其解压缩为位图,并与帧位图叠加(您可能需要在此处使用高分辨率版本的框架),并将两者结合起来(基于 https://stackoverflow.com / a / 4863551/192373 ):
Next, you capture the jpeg as usual, unpack it to bitmap, overlay with the frame bitmap (you may need a hi-res version of your frame here) and combine the two (based on https://stackoverflow.com/a/4863551/192373):
public Bitmap combineImages(Bitmap picture, Bitmap frame) {
Bitmap bmp = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(bmp);
comboImage.drawBitmap(picture, 0f, 0f, null);
comboImage.drawBitmap(frame, 0f, 0f, null);
return bmp;
}
这篇关于如何在框架后面显示预览相机并拍摄包含框架的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!