Need help with altering the Bitmaps in an ImageList to switch the black pixels to yellow, they are being used as images for a UICommandBar (screenshot and attempt below)
The code gets executed, with GetPixel condition and then SetPixel, but the images are not changed. Maybe related to ImageListStreamer or not the right time to swap those pixels.
rtfeditor.cs
this.imageList1.ImageStream = ( (System.Windows.Forms.ImageListStreamer)(resources.GetObject( "imageList1.ImageStream" ) ) );
this.imageList1 = ColorSpace.ProcessHighContrast(this.imageList1);
Utils\ColorSpace.cs
public static System.Windows.Forms.ImageList ProcessHighContrast(System.Windows.Forms.ImageList imageList)
{
if (System.Windows.Forms.SystemInformation.HighContrast)
{
foreach (System.Drawing.Bitmap imageListImage in imageList.Images)
{
for (int i = 0; i < imageListImage.Width; i++)
{
for (int j = 0; j < imageListImage.Height; j++)
{
Color color = imageListImage.GetPixel(i, j);
if (System.Drawing.Color.FromArgb(255, 0, 0, 0).Equals(color))
imageListImage.SetPixel(i, j, System.Drawing.SystemColors.WindowText);
}
}
}
}
return imageList;
}
Solved
Hans Passant's comment was critical for resolving this (see quoted comment below) + changing the order of the call of ProcessHighContrast (now first) with the assignment of the ImageList to the Janus.Windows.UI.CommandBars.UICommandBar (now second). New method and calling code below.
rtfeditor.cs
Utils\ColorSpace.cs