capturing image from camera and overlaying another

2020-02-07 06:50发布

问题:

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

回答1:

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