Android: Draw image on Camera Preview

故事扮演 提交于 2019-12-25 01:18:06

问题


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();
}

回答1:


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.



来源:https://stackoverflow.com/questions/12689095/android-draw-image-on-camera-preview

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