_SBradley_
Active member
If I run the following code on a 16-colour bitmap, the changes to the palette are not included in the saved image. However, the image displayed in the form is as I expected (black & white). Am I doing something wrong, or is this a bug?
[CS]
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
class Test
{
static void Main(string[] args)
{
Bitmap bmp = new Bitmap(args[0]);
ColorPalette pal = bmp.Palette;
for (int i = 0; i < pal.Entries.Length; ++i)
pal.Entries = i == 0 ? Color.Black : Color.White;
bmp.Palette = pal;
bmp.Save("new.bmp");
new ImgForm(bmp).ShowDialog();
}
}
class ImgForm : Form
{
public ImgForm(Bitmap bmp)
{
m_Bitmap = bmp;
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(m_Bitmap, ClientRectangle);
}
private Bitmap m_Bitmap;
}
[/CS]
[CS]
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
class Test
{
static void Main(string[] args)
{
Bitmap bmp = new Bitmap(args[0]);
ColorPalette pal = bmp.Palette;
for (int i = 0; i < pal.Entries.Length; ++i)
pal.Entries = i == 0 ? Color.Black : Color.White;
bmp.Palette = pal;
bmp.Save("new.bmp");
new ImgForm(bmp).ShowDialog();
}
}
class ImgForm : Form
{
public ImgForm(Bitmap bmp)
{
m_Bitmap = bmp;
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(m_Bitmap, ClientRectangle);
}
private Bitmap m_Bitmap;
}
[/CS]