从相机捕获图像并在保存之前叠加另一个位图 [英] capturing image from camera and overlaying another bitmap before we save it

查看:72
本文介绍了从相机捕获图像并在保存之前叠加另一个位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里tempdata是从摄像机捕获的数据,savephoto(Bitmap)是一种用于保存从摄像机捕获的图像的方法,它执行准确, 继续播放[2] 我正在叠加另一个位图,并且在我调用savephoto(p)时 它正在存储卡中创建一个空文件... 不保存任何图像. 如何将两个位图彼此叠加

here tempdata is the data captured from camera, savephoto(Bitmap) is a method am using to save the image taken from camera, and it is executing accurately ,, BUt on [2] i am overlaying another bitmap ,, and when i am calling the savephoto(p) it is creating an empty file in the memorycard ... not saving any image. how can i overlay the two bitmap on top of each other

[1]File Imgname = Environment.getExternalStorageDirectory();
Bitmap bmp = BitmapFactory.decodeByteArray(tempdata,0,tempdata.length);
imv.setImageBitmap(bmp);
savePhoto(bmp);

[2]Bitmap bmp2 = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
Bitmap b = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.drawBitmap(bmp, 0,0, null);
canvas.drawBitmap(bmp2, 50, 50, null);
savePhoto(b);

任何帮助将不胜感激 谢谢

any help will be greatly appreciated thanx

推荐答案

从相机获取位图(假定bitmap1)并将位图叠加在bitmap1顶部(假定bitmap2)之后,您可以执行以下操作 用您的位图调用这个overlayMark(),它将返回覆盖位图,它是您所需的位图.您可以保存该位图.

you can do like this after getting after getting bitmap from camera (assume bitmap1) and your bitmap to overlay on top of bitmap1 (assume bitmap2) call this overlayMark() with your bitmaps it will return overlay bitmap that is your required bitmap . you can save that bitmap..

private Bitmap overlayMark(Bitmap bmp1, Bitmap bmp2)    { 
   int bh = originalBitmap.getHeight();
   int bw = originalBitmap.getWidth();
   Bitmap bmOverlay = Bitmap.createBitmap(bw,bh,Bitmap.Config.ARGB_8888); 
   Canvas canvas = new Canvas(bmOverlay); 
   canvas.drawBitmap(bmp1, 0, 0, null);
   canvas.drawBitmap(bmp2, 0,0, null);
   return bmOverlay;
} 

这篇关于从相机捕获图像并在保存之前叠加另一个位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆