Skip to content

Instantly share code, notes, and snippets.

@RyuaNerin
Last active August 29, 2015 14:02
Show Gist options
  • Save RyuaNerin/15b9e1105e9418da1282 to your computer and use it in GitHub Desktop.
Save RyuaNerin/15b9e1105e9418da1282 to your computer and use it in GitHub Desktop.
public static void Png32ToPna(Bitmap image)
{
BitmapData data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, image.PixelFormat);
try
{
unsafe
{
byte* ptr = (byte*)data.Scan0;
for (int i = 0; i < data.Height; i++)
{
for (int j = 0; j < data.Width; j++)
{
ptr[1] = ptr[2] = ptr[3] = ptr[0];
ptr += 3;
}
ptr += data.Stride - data.Width * 4;
}
}
}
finally
{
image.UnlockBits(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment