當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。