2013-02-11 41 views

回答

3

這裏是我結束了在OpenTK做(應該很容易轉換爲C++或其他的OpenGL/OpenGL ES的啓用語言):

public Bitmap GetBitmap() 
{ 
    int fboId; 
    GL.Ext.GenFramebuffers(1, out fboId); 
    CheckGLError(); 
    GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, fboId); 
    CheckGLError(); 
    GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, TextureId, 0); 
    CheckGLError(); 

    Bitmap b = new Bitmap(Width, Height); 
    var bits = b.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); 
    GL.ReadPixels(Rect.Left, Rect.Top, Width, Height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bits.Scan0); 
    GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); 
    GL.Ext.DeleteFramebuffers(1, ref fboId); 
    b.UnlockBits(bits); 

    return b; 
} 
+0

FYI:我刪除了我的答案,因爲它是進入完全相反的方向。 – datenwolf 2013-02-19 12:13:34

+0

感謝您的幫助datenwolf,聽起來像你知道很多有關OpenGL – jjxtra 2013-02-19 16:45:38

+0

我不需要位圖,只是在特定的座標的RGB值,這仍然是最好的辦法? – 2016-04-18 05:05:26

相關問題