Skip to content

Instantly share code, notes, and snippets.

@PathogenDavid
Created June 14, 2014 03:34
Show Gist options
  • Save PathogenDavid/601f19a6ddff7b00359c to your computer and use it in GitHub Desktop.
Save PathogenDavid/601f19a6ddff7b00359c to your computer and use it in GitHub Desktop.
Texture.Download method
/// <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