4
Answers

GDI+ Buffered Image and redraw problem

Robert

Robert

14y
10.1k
1
Hello, this is example from Core C# and .Net book.
Draw one flag on button1 click, on button2 click draw the same flag but reverse colors.
Everything works, but there is problem. Panel has to be redrawn, because now when I minimize the form image that I drew disappears.


// reverse colors
private void button3_Click(object sender, EventArgs e)
{
Graphics g = pan.CreateGraphics();
string fname = "c:\\flag.gif";
Bitmap bmp = new Bitmap(fname);
Bitmap bmpMem = new Bitmap(bmp.Width,bmp.Height);
Graphics gMem = Graphics.FromImage(bmpMem);
gMem.DrawImage(bmp,0,0); /
/ Draw flag to memory
Color cnRed = Color.FromArgb(255,214,41,33);
for (int y=0; y 240) bmpMem.SetPixel(x,y, cnRed);
else
bmpMem.SetPixel(x,y,Color.White);
}
}
g.DrawImage(bmpMem,0,0);
// Display reversed flag on panel
gMem.Dispose();
g.Dispose();
}

// draw image
void button1_Click(object sender, EventArgs e)
{
Graphics g = pan.CreateGraphics();
string fname = "c:\\flag.gif";
Bitmap bmp = new Bitmap(fname);
g.DrawImage(bmp,0,0);
g.Dispose();
}

Project http://www.sendspace.com/file/66rc3f

If someone knows how to keep this image on panel please answer.
Answers (4)