安卓:借鉴相机preVIEW图像 [英] Android: Draw image on Camera Preview

查看:265
本文介绍了安卓:借鉴相机preVIEW图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建相机preVIEW绘制图像的相机应用程序。当相机正在运行我想补充一个图像文件:相机preVIEW(例如image.png)。
这里是code,我要运行相机,但我不知道code,增加/绘制image.png

 意向意图=新意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
mImageCaptureUri = Uri.fromFile(新文件(Environment.getExternalStorageDirectory()
IMG_+将String.valueOf(System.currentTimeMillis的())+.JPG));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,mImageCaptureUri);尝试{
    intent.putExtra(回归数据,真正的);
    startActivityForResult(意向,PICK_FROM_CAMERA);
}赶上(ActivityNotFoundException E){
    e.printStackTrace();
}


解决方案

您不能覆盖​​物品的摄像头,除非相机preVIEW是在你的应用程序本身。使用意图不会允许你这样做。

一位来自我的书,临Android的增强现实的例子应用程序,向您展示了如何做到这一点。你可以找到该应用的开源$ C ​​$ C <一个href=\"https://github.com/RaghavSood/ProAndroidAugmentedReality/tree/master/Pro%20Android%20AR%203%20Widget%20Overlay\"相对=nofollow>这里。

从本质上讲,你必须使用 SurfaceView 显示相机数据,然后使用 RelativeLayout的或的的FrameLayout 画在它上面的东西。

I want to create a Camera application that draws an image on the camera preview. When the camera is running I want to add an image file (example : image.png) on the camera preview. Here is the code that I have to run the camera, but I don't know the code that adds/draws the image.png

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
"IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);

try {
    intent.putExtra("return-data", true);
    startActivityForResult(intent, PICK_FROM_CAMERA);
} catch (ActivityNotFoundException e) {
    e.printStackTrace();
}

解决方案

You can't overlay items on the camera, unless the camera preview is in your app itself. Using the intent won't allow you to do this.

One of the example apps from my book, Pro Android Augmented Reality, shows you how to do this. You can find the open source code for that app here.

Essentially, you must use a SurfaceView to display the camera data, and then use a RelativeLayout or FrameLayout to draw things on top of it.

这篇关于安卓:借鉴相机preVIEW图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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