2013-12-16 76 views
1

美好的一天。ANDROID:將OpenGL onDraw轉換爲位圖,然後在ImageView中顯示位圖

我在自己的imageView中顯示來自openGL的位圖時出現問題。

首先,我創建的3D OpenGL的對象中(像立方體,球體等)

然後,我的openGL的視圖的onDraw轉換爲位圖(我用這個代碼)

public static Bitmap createBitmapFromGLSurface(int x, int y, int w, int h, GL10 gl) 
     throws OutOfMemoryError { 
    int bitmapBuffer[] = new int[w * h]; 
    int bitmapSource[] = new int[w * h]; 
    IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer); 
    intBuffer.position(0); 

    try { 
     gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer); 
     int offset1, offset2; 
     for (int i = 0; i < h; i++) { 
      offset1 = i * w; 
      offset2 = (h - i - 1) * w; 
      for (int j = 0; j < w; j++) { 
       int texturePixel = bitmapBuffer[offset1 + j]; 
       int blue = (texturePixel >> 16) & 0xff; 
       int red = (texturePixel << 16) & 0x00ff0000; 
       int pixel = (texturePixel & 0xff00ff00) | red | blue; 
       bitmapSource[offset2 + j] = pixel; 
      } 
     } 
    } catch (GLException e) { 
     return null; 
    } 

    return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888); 
} 

嗯,它捕獲了onDraw的視圖並將其轉換爲位圖,但我需要的是將openGL作爲後臺進程,將其視圖轉換爲位圖,在主要活動的imageview中顯示位圖。

我刪除了

setContentView(ourSurfaceView) 
我mainActivity

但刪除它,改變我的layout.xml 位圖我從openGL的創建後不能正常工作。 (對不起,我的英語)

THANKs in advanced。 :)

回答

相關問題