Skip to content

Instantly share code, notes, and snippets.

@dellis1972
Created March 20, 2013 11:38
Show Gist options
  • Save dellis1972/5204016 to your computer and use it in GitHub Desktop.
Save dellis1972/5204016 to your computer and use it in GitHub Desktop.
private static void PreMultiplyImage(string infile, string outfile)
{
using (System.Drawing.Image image = System.Drawing.Image.FromFile(infile))
{
int w = image.Width;
int h = image.Height;
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
for (int i = 0; i != bitmap.Width; ++i)
{
for (int j = 0; j != bitmap.Height; ++j)
{
System.Drawing.Color pixel = bitmap.GetPixel(i, j);
System.Drawing.Color prepxiel = System.Drawing.Color.FromArgb(
pixel.A,
(pixel.R * pixel.A / 255),
(pixel.G * pixel.A / 255),
(pixel.B * pixel.A / 255)
);
bitmap.SetPixel(i,j,prepxiel);
}
}
bitmap.Save(outfile);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment