Question

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();
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top