Created
June 14, 2014 03:34
-
-
Save PathogenDavid/601f19a6ddff7b00359c to your computer and use it in GitHub Desktop.
Texture.Download method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Downloads this texture from the GPU. | |
/// </summary> | |
/// <returns>A bitmap representing this texture. You are responsible for disposing it.</returns> | |
public Bitmap Download() | |
{ | |
Bitmap bitmap = null; | |
try | |
{ | |
bitmap = new Bitmap(Width, Height); | |
BitmapData data = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); | |
Bind(TextureTarget.Texture2D); | |
GL.GetTexImage(TextureTarget.Texture2D, 0, PixelFormat.Rgba, PixelType.UnsignedByte, data.Scan0); | |
bitmap.UnlockBits(data); | |
return bitmap; | |
} | |
catch | |
{ | |
if (bitmap != null) { bitmap.Dispose(); } | |
throw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment