在android中与相机捕获的图像叠加图像
Posted
技术标签:
【中文标题】在android中与相机捕获的图像叠加图像【英文标题】:Image overlay with camera captured image in android 【发布时间】:2012-01-11 05:32:04 【问题描述】:我需要用相机拍照,同时在相机视图顶部显示叠加图像。拍照后,我需要保存用户在拍照时看到的内容。任何人都可以建议我吗?请。
【问题讨论】:
你有想过这个吗?我也需要这样做。已让相机使用叠加层,但我无法将两者一起保存为一张图像。 capturing image from camera and overlaying another bitmap before we save it的可能重复 【参考方案1】: public void onPictureTaken(byte[] data, Camera camera)
Bitmap cameraBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
wid = cameraBitmap.getWidth();
hgt = cameraBitmap.getHeight();
Bitmap newImage = Bitmap.createBitmap(wid , hgt , Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newImage);
canvas.drawBitmap(cameraBitmap, 0f, 0f, null);
Drawable drawable = getResources().getDrawable(R.drawable.d);
drawable.setBounds(20 ,20, 260, 160);
drawable.draw(canvas);
File storagePath = new File(Environment.getExternalStorageDirectory() + "/Vampire Photos/");
storagePath.mkdirs();
File myImage = new File(storagePath,Long.toString(System.currentTimeMillis()) + ".jpg");
try
FileOutputStream out = new FileOutputStream(myImage);
newImage.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
catch(FileNotFoundException e)
Log.d("In Saving File", e + "");
catch(IOException e)
Log.d("In Saving File", e + "");
camera.startPreview();
drawable = null;
newImage.recycle();
newImage = null;
cameraBitmap.recycle();
cameraBitmap = null;
;
【讨论】:
以上是关于在android中与相机捕获的图像叠加图像的主要内容,如果未能解决你的问题,请参考以下文章