Created
October 19, 2011 09:28
-
-
Save jlebrech/1297841 to your computer and use it in GitHub Desktop.
Set copy the left pixel and make any instances of that color transparent
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
ExtendedImage _img = sender as ExtendedImage; | |
byte transpCorner = _img.Pixels[0 * _img.PixelWidth + 0]; // top left pixel | |
byte[] newPixels = _img.Pixels; | |
for (int xp = 0; xp < _img.PixelWidth; xp++) | |
{ | |
for (int yp = 0; yp < _img.PixelHeight; yp++) | |
{ | |
int r = 0, g = 0, b = 0, alpha = 0; | |
int idx = xp * _img.PixelWidth + yp; | |
byte r1 = (byte)(r * (alpha / 255d)); | |
byte g1 = (byte)(g * (alpha / 255d)); | |
byte b1 = (byte)(b * (alpha / 255d)); | |
if (newPixels[idx] == transpCorner) // if the current pixel is the same as the transpCorner value then set it's alpha to 0 | |
{ | |
newPixels[idx] = (byte)((alpha << 24) | (r1 << 16) | (g1 << 8) | b1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment