Android 中相机捕获图像的图像叠加

2024-04-16

我需要用相机拍照,同时在相机视图顶部显示叠加图像。拍照后,我需要保存用户在拍照时看到的内容。有人可以建议我吗?请。


  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;
 } };
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 中相机捕获图像的图像叠加 的相关文章

随机推荐