带摄像头的图像叠加在android系统捕捉到的图像 [英] Image overlay with camera captured image in android

查看:290
本文介绍了带摄像头的图像叠加在android系统捕捉到的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要拍照与相机,并在同一时间上显示的摄像机视图的顶部叠加图像。拍摄照片后,我需要保存用户所看到的,而拍照。任何人都可以给我建议?请。


解决方案

 公共无效onPictureTaken(字节[]数据,相机摄像头){
  位图cameraBitmap = BitmapFactory.de codeByteArray的(数据,0,data.length);  WID = cameraBitmap.getWidth();
  HGT = cameraBitmap.getHeight();
 位图newImage = Bitmap.createBitmap(WID,HGT,Bitmap.Config.ARGB_8888);  帆布帆布=新的Canvas(newImage);  canvas.drawBitmap(cameraBitmap,0F,0F,NULL);  可绘制可绘制= getResources()getDrawable(R.drawable.d)。
  drawable.setBounds(20,20,260,160);
  drawable.draw(画布);  文件storagePath =新的文件(Environment.getExternalStorageDirectory()+/吸血鬼图片/);
  storagePath.mkdirs();  文件MYIMAGE =新的文件(storagePath,Long.toString(System.currentTimeMillis的())+.JPG);  尝试
  {
    FileOutputStream中出=新的FileOutputStream(MYIMAGE);
    newImage.com preSS(Bitmap.Com pressFormat.JPEG,90出);
    了out.flush();
    out.close();
  }
  赶上(FileNotFoundException异常E)
  {
   Log.d(在保存文件E +);
  }
  赶上(IOException异常E)
  {
    Log.d(在保存文件E +);
  }  camera.start preVIEW();  可绘制= NULL;  newImage.recycle();
  newImage = NULL;  cameraBitmap.recycle();
  cameraBitmap = NULL;
 }};

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.

解决方案

  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系统捕捉到的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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