How to display preview camera behind a frame and take picture include frame

五迷三道 提交于 2020-05-28 07:58:07

问题


I'm trying build a camera app in android using camera API.

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

Please see the two pictures below:

Frame in resource folder : https://i.stack.imgur.com/AaNIQ.png

The photo I want to achieve: 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.

Thank you so much.


回答1:


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.

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; 
} 


来源:https://stackoverflow.com/questions/47961884/how-to-display-preview-camera-behind-a-frame-and-take-picture-include-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!