Log in or register to post comments

How to capture AR view

May 19, 2013 - 2:18am #1

i want to capture ar view in my app.

i have been read this thread:
https://developer.vuforia.com/forum/faq/android-how-can-i-capture-ar-view

and i also do what AlessandroB say on this thread:

https://developer.vuforia.com/forum/qcar-api/how-make-screenshot

i try on my project, it didn't show anyerror. but i also didn't got my screenshot.

 

i didn't see any error in LogCat. i think i must show my code to you, so this my code on ImageTargetsRendered.java

 

public boolean mTakeScreenshot = false;
    public void takeScreenshot() {
      mTakeScreenshot = true;    
    }
    
    public void onDrawFrame(GL10 gl)
    {
        if (!mIsActive)
            return;
 
        // Update render view (projection matrix and viewport) if needed:
            //mActivity.updateRenderView();
 
        // Call our native function to render content
        renderFrame();
         
        // make sure the OpenGL rendering is finalized
        GLES20.glFinish();
        
        
        if (mTakeScreenshot==true) {
            saveScreenShot(0, 0, mViewWidth, mViewHeight, "test.png");
            mTakeScreenshot = false;
        }
    }

 

that the last part from your code and i add takeScreenshot method that i call in ImageTargets.java with this code:

public void takeScreenshot2(View view) {
        ImageTargetsRenderer ambil = new ImageTargetsRenderer();
        button1.setVisibility(View.INVISIBLE);
        ambil.takeScreenshot();
        button1.setVisibility(View.VISIBLE);
      }

 

there is any wrong code that i add??

How to capture AR view

June 3, 2013 - 11:02pm #13

If you can capture the overlayView (with black background) and the underlying AR view in 2 separate bitmaps, 

then what you could try is to combine those bitmaps into one, by manipulating their pixels;

for instance, you could iterate over each pixel of the overlay bitmap, and replace every black pixel with the corresponding pixel from the AR view.

See the Android Bitmap API reference page for how to manipulate pixels:

http://developer.android.com/reference/android/graphics/Bitmap.html

 

How to capture AR view

June 3, 2013 - 9:22pm #12

Thanks for your assistance.

I tried the following piece to save the screenshot of the content view (overlay). This works fine to save the overlay content albeit with a black background.

				View v = mGlView.getRootView();
			    v.setDrawingCacheEnabled(true);
			    Bitmap capturedBitmap = Bitmap.createBitmap(v.getDrawingCache());
			    v.setDrawingCacheEnabled(false);

Please advice if you are aware of a technique to either programatically overlap one image on another, or capture both camera and content view.

How to capture AR view

June 3, 2013 - 11:32am #11

If you are trying to capture the overlay too, that will not work, because the technique that I illustrate to capture the AR view is only meant for capturing OpenGL-based content.

If you need to capture "everthing" including the overlay, you will need to use a different approach, for instance using 3rd party libraries or tools to capture the screen; that's something you may want to search for in some Android specialized forums, as it is a more general problem.

How to capture AR view

June 3, 2013 - 10:09am #10

I can share the code for CloudReco and Renderer from theproject to help you understand it better. Please let me know

How to capture AR view

June 2, 2013 - 10:32am #9

I have some imageView being displayed on the camera_overlay_layout. The intent is to take a screenshot with this imageview and the video background.

I have these images being displayed on the screen when I press the capture button.

How to capture AR view

June 2, 2013 - 5:45am #8

Just for confirmation, do you see the 3D augmentation on the screen at the time when you click the button to save the screenshot ?

 

How to capture AR view

June 2, 2013 - 12:06am #7

takeScreenShot method just sets the flag to take snapshot.

 

public void takeScreenShot(){

takeScreenshot = true;

}

 

Other methods are as follows:

	public void onDrawFrame(GL10 gl)
	{
		if (!mIsActive)
		{
			return;
		}

		// Update render view (projection matrix and viewport) if needed:
		mActivity.updateRenderView();

		// Call our native function to render content
		renderFrame();

		// make sure the OpenGL rendering is finalized
		GLES20.glFinish();

		if ( takeScreenshot ) {
			saveScreenShot(0, 0, mViewWidth, mViewHeight, "test.png", gl);
			takeScreenshot = false;
		}
	}

 

 

 

	private void saveScreenShot(int x, int y, int w, int h, String filename, GL10 gl) {
		Bitmap bmp = grabPixels(x, y, w, h);
		try {
			String path = Environment.getExternalStorageDirectory() + "/" + filename;
			DebugLog.LOGD(path);

			File file = new File(path);
			file.createNewFile();

			FileOutputStream fos = new FileOutputStream(file);
			bmp.compress(CompressFormat.PNG, 100, fos);

			fos.flush();

			fos.close();

		} catch (Exception e) {
			DebugLog.LOGD(e.getStackTrace().toString());
		}
	}
	private Bitmap grabPixels(int x, int y, int w, int h) {
		int b[] = new int[w * (y + h)];
		int bt[] = new int[w * h];
		IntBuffer ib = IntBuffer.wrap(b);
		ib.position(0);

		GLES20.glReadPixels(x, 0, w, y + h, 
				GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ib);

		for (int i = 0, k = 0; i < h; i++, k++) {
			for (int j = 0; j < w; j++) {
				int pix = b[i * w + j];
				int pb = (pix >> 16) & 0xff;
				int pr = (pix << 16) & 0x00ff0000;
				int pix1 = (pix & 0xff00ff00) | pr | pb;
				bt[(h - k - 1) * w + j] = pix1;
			}
		}

		Bitmap sb = Bitmap.createBitmap(bt, w, h, Bitmap.Config.ARGB_8888);
		return sb;
	}

I also tried calling the glReadPixels method using the GL10 instance in onDrawFrame method instead. But no avail.

Please help

How to capture AR view

June 1, 2013 - 9:27am #6

Hi, 

what does your takeScreenshot method does exactly ?

 

How to capture AR view

June 1, 2013 - 3:41am #5

Hi Guys,

I am looking to integrate this in the CloudReco example. For this I followed the post https://developer.vuforia.com/forum/faq/android-how-can-i-capture-ar-view.

I'm setting the flag to take screenshot on click of button in CloudReco.java.

However, this only saves the video feed. The content shown in GL View does not get captured.

Here is the code snippet for setting up the flag, method initApplicationAR:

 

mCameraButton = (Button) mUILayout

.findViewById(R.id.buttonCapture);

 

mCameraButton.setOnClickListener(new View.OnClickListener() {

 

@Override

public void onClick(View arg0) {

mRenderer.takeScreenShot();

 

}

});

 

Please help.

How to capture AR view

May 19, 2013 - 6:17am #4

you're welcome

How to capture AR view

May 19, 2013 - 2:48am #3

did you mean this code "mRenderer = new ImageTargetsRenderer();" ?

owh yes, that the problem. i got my screenshot. thanks for your help.

How to capture AR view

May 19, 2013 - 2:31am #2

Hi, I don't see why you instantiate a new Renderer in takeScreenshot2

ImageTargetsRenderer ambil = new ImageTargetsRenderer();

this is probably the cause of the issue; you must use only one renderer in your app

(the one which is already created in ImageTargets.java)

 

Log in or register to post comments