I am creating icons on the fly for a set of winforms/clickonce applications. I have it all working by following http://www.vbforums.com/showthread.php?396650-Create-Valid-Icon-Files!-In-24-bit-true-color and adapting to C#.
I would like to have a different background colour for different environments, e.g. Live has a white background, QA is yellow, and DEV should be orange. All seems pretty easy and I have been able to create my temp.ico with white and yellow backgrounds using the following:
private static void CreateTempIcon(int size)
{
var myBmp = new Bitmap(size, size);
var graphics = Graphics.FromImage(myBmp);
var bgColor = GetIconBgColor();
graphics.Clear(bgColor);
var myIcon = Icon.FromHandle(myBmp.GetHicon());
var st = new FileStream(TempIcon, FileMode.Create);
var wr = new BinaryWriter(st);
myIcon.Save(st);
myBmp.Dispose();
wr.Close();
}
private static Color GetIconBgColor()
{
switch (ApplicationSettings.Branch)
{
case BranchType.Live:
return Color.White;
case BranchType.Dev:
return Color.Orange;
case BranchType.QA:
return Color.Yellow;
default:
throw new ArgumentOutOfRangeException();
}
}
All of the colours show correctly, except for orange which shows as red.
I have tried various things including
Creating the bitmap with a pixelformat
var myBmp = new Bitmap(size, size, PixelFormat.Format32bppArgb);
Creating the colour from argb
return Color.FromArgb(255, 255, 165, 0);
and variations on using/not using alpha channels, using Color.FromColor, etc. It's like my colour palette is limited to only a few basic colours. The link above says the initial icon is created in 24 bit colour which as far as I know includes orange.
I don't know a huge amount about image formats (clearly!). Could anyone point me in the direction of what I am doing wrong?