[英]Merge Camera preview with a image?
I am trying to make a composite image from a camera preview and an ImageView
that was above it. 我正在尝试从相机预览和上面的
ImageView
制作合成图像。 I have one image that is a transparent png which is set on an imageview like this 我有一个透明的png图像,它在像这样的imageview上设置
ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.one);
I then add it to the framelayout which is already showing my camera preview (inherits SurfaceView) like so: 然后我将它添加到framelayout,它已经显示我的相机预览(继承SurfaceView),如下所示:
preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(cp); //cp is a reference to a camera preview object
preview.addView(iv);
My imageview's picture is this: 我的imageview的图片是这样的:
And the screen is something like this (I had to take a the pic from another camera since the DDMS screenshot wasn't showing the preview only the image and a black screen, don't know if that's a relevant though): 屏幕是这样的(我不得不从另一台相机拍摄照片,因为DDMS截图没有显示预览图像和黑屏,不知道这是否相关):
Now my task is to take that picture with the imageview. 现在我的任务是用imageview拍摄那张照片。 I came up with two approaches, both of which I do not know whether they can or cannot be implemented
我想出了两种方法,我不知道它们是否可以实现
What I want to know is which one these approaches is possible and how can it be done? 我想知道的是这些方法可以采用哪种方法以及如何实现? or is there a better way to get this done?
还是有更好的方法来完成这项工作?
Assuming you already have image in form of byte[] data
from jpeg callback. 假设你已经有来自jpeg回调的
byte[] data
形式的图像。
Decode the image into a mutable bitmap: 将图像解码为可变位图:
Bitmap photo = BitmapFactory.decodeByteArray(data, 0, data.length); photo = photo.copy(photo.getConfig(), true);
Read the overlay: 阅读叠加层:
Bitmap overlay = BitmapFactory.decodeResource(getResources(), R.drawable.one);
Draw overlay on the photo: 在照片上绘制叠加层:
Canvas canvas = new Canvas(photo); canvas.drawBitmap(overlay, new Matrix(), null);
Now, photo
should contain your image. 现在,
photo
应该包含您的图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.