I'm at changing Icons Color, wich works so far, but now my Pixels are loosing their transparency, even while I actively try to prevent this. Here is my code:
private static void ChangeColor()
{
foreach(MultiIcon mi in listMi)
foreach (SingleIcon si in mi)
for (int n = 0; n < si.Count(); n++)
{
IconImage ii = si[n];
Bitmap bmp = new Bitmap(ii.Image);
for (int w = 0; w < bmp.Width; w++)
for (int h = 0; h < bmp.Height; h++)
if (bmp.GetPixel(w, h).R == identifier - uncertanty && bmp.GetPixel(w, h).R == identifier + uncertanty)
bmp.SetPixel(w, h, Color.FromArgb(bmp.GetPixel(w, h).A, r, g, b));
ii.Set(bmp, null, Color.Transparent);
}
}
With this line, I take my original alpha-value and reuse it when setting my new (with changed color) pixel.
bmp.SetPixel(w, h, Color.FromArgb(bmp.GetPixel(w, h).A, r, g, b));
This is used for Saving the file. MultiIcon comes from IconLib:
http://www.codeproject.com/Articles/16178/IconLib-Icons-Unfolded-MultiIcon-and-Windows-Vista
mi.Save(NewPath(pathArray[i]), MultiIconFormat.ICO);
Another Issue is, that my Icon (but not the single icon-frames) are double as hight while still the same width.
EDIT:
I changed the PixelFormat to Format32bppPArgb which should be, what I need for transparecy, also made sure the Bitmap gets created Pixel by Pixel from the original, instead of copying and changing the it. Still, the same issue occures.
This is the new Code:
for (int n = 0; n < si.Count(); n++)
{
IconImage ii = si[n];
Bitmap bmp = new Bitmap(ii.Image.Height, ii.Image.Width, PixelFormat.Format32bppPArgb);
for (int w = 0; w < bmp.Width; w++)
for (int h = 0; h < bmp.Height; h++)
{
if (si[n].Image.GetPixel(w, h).R > identifier - uncertanty && si[n].Image.GetPixel(w, h).R < identifier + uncertanty)
bmp.SetPixel(w, h, Color.FromArgb(si[n].Image.GetPixel(w, h).A, r, g, b));
else
{
Color c = Color.FromArgb(
si[n].Image.GetPixel(w, h).A,
si[n].Image.GetPixel(w, h).R,
si[n].Image.GetPixel(w, h).G,
si[n].Image.GetPixel(w, h).B
);
bmp.SetPixel(w, h, c);
}
}
ii.Set(bmp, null, Color.Transparent);
}