当前位置: 首页>>代码示例>>Java>>正文


Java GL10.glReadPixels方法代码示例

本文整理汇总了Java中javax.microedition.khronos.opengles.GL10.glReadPixels方法的典型用法代码示例。如果您正苦于以下问题:Java GL10.glReadPixels方法的具体用法?Java GL10.glReadPixels怎么用?Java GL10.glReadPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.microedition.khronos.opengles.GL10的用法示例。


在下文中一共展示了GL10.glReadPixels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: takeScreenSnapshot

import javax.microedition.khronos.opengles.GL10; //导入方法依赖的package包/类
public Bitmap takeScreenSnapshot(GL10 gl)	{
	int width = (int) mdChartWindowWidth;
	int height = (int) mdChartWindowHeight;
    int screenshotSize = width * height;
    int pixelsBuffer[] = new int[screenshotSize];
    try {
	    ByteBuffer bb = ByteBuffer.allocateDirect(screenshotSize * 4);
	    bb.order(ByteOrder.nativeOrder());
	    // this statement does not work in the landscape mode of galaxy express. Seems that it cannot support so large height (lines).
	    //gl.glReadPixels(0, 0, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);
	    gl.glReadPixels(0, 0, width, height/2, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);
	    bb.asIntBuffer().get(pixelsBuffer);
	    gl.glReadPixels(0, height/2, width, height/2, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);
	    int pixelsBufferBottom[] = new int[screenshotSize];
	    bb.asIntBuffer().get(pixelsBufferBottom);
	    for (int idx = screenshotSize/2; idx < screenshotSize; idx ++)	{
	    	pixelsBuffer[idx] = pixelsBufferBottom[idx - screenshotSize/2];
	    }
	    bb = null;
    } catch (OutOfMemoryError  e)	{
    	// ByteBuffer.allocateDirect(screenshotSize * 4); could be out of memory
    	// in general, OutOfMemoryError should not be handled and developer should let JVM die.
    	// however, in this case, we know what statement causes the out of memory error
    	// and other threads are not affected. So it is ok to catch it.
    }

    for (int i = 0; i < screenshotSize; ++i) {
        // The alpha and green channels' positions are preserved while the red and blue are swapped
        pixelsBuffer[i] = ((pixelsBuffer[i] & 0xff00ff00)) | ((pixelsBuffer[i] & 0x000000ff) << 16) | ((pixelsBuffer[i] & 0x00ff0000) >> 16);
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixelsBuffer, screenshotSize-width, -width, 0, 0, width, height);
    return bitmap;
}
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:36,代码来源:OGLChart.java


注:本文中的javax.microedition.khronos.opengles.GL10.glReadPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。