Image overlay with camera captured image in android

↘锁芯ラ 提交于 2019-12-07 06:06:11

问题


I need to take a picture with the camera and at the same time show an overlay image on top of the camera view. After the picture is taken, i need to save what the user saw while taking the picture. Can anyone suggest me? Please.


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


来源:https://stackoverflow.com/questions/8352062/image-overlay-with-camera-captured-image-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!