Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
creating Android GraphicBuffer via Reflection
try {
Class c_GraphicBuffer = Class.forName("android.view.GraphicBuffer");
Log.e(LOG_TAG, "GraphicBuffer " + c_GraphicBuffer);
Method GraphicBuffer_create = c_GraphicBuffer.getMethod("create", new Class[] { int.class, int.class, int.class, int.class, });
Log.e(LOG_TAG, "Method GraphicBuffer_create " + GraphicBuffer_create);
Object hGraphicBuffer = GraphicBuffer_create.invoke(null, 1920, 1080, 1, 0x3 | 0x30 | 0x100);
Log.e(LOG_TAG, "Created GraphicBuffer " + hGraphicBuffer);
Method GraphicBuffer_lockCanvas = c_GraphicBuffer.getMethod("lockCanvas", new Class[] {});
Log.e(LOG_TAG, "Method GraphicBuffer_lockCanvas " + GraphicBuffer_lockCanvas);
Method GraphicBuffer_unlockCanvasAndPost = c_GraphicBuffer.getMethod("unlockCanvasAndPost", new Class[] {Canvas.class});
Log.e(LOG_TAG, "Method GraphicBuffer_unlockCanvasAndPost " + GraphicBuffer_unlockCanvasAndPost);
Canvas canvas = (Canvas)GraphicBuffer_lockCanvas.invoke(hGraphicBuffer);
Log.e(LOG_TAG, "Locked Canvas");
GraphicBuffer_unlockCanvasAndPost.invoke(hGraphicBuffer, canvas);
Log.e(LOG_TAG, "Unlocked Canvas");
}
catch (Exception e)
{
Log.e(LOG_TAG, "GraphicBuffer not found, oh..");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment