Ok, I have a function that creates and draws a maze on a Panel in a Winforms App. Then I sniped some code that manages to save the image of the panel to a bmp file.
WHY it's any harder than panel.canvas.savetofile is just stupid.
BUT!
If the panel is off the screen edge, or if it's obscured in any way, I get blank rectangle on the image (again stupid).
What I really want is what I've had for 10 years in Delphi.
I want to make my routine create the image in memory (even if the image is bigger than the screen). I want to be able to...
1. copy that image to the panel during a paint event
2. save the entire image to a file.
What I have run into so far is typical Microsoft.
First there are too may objects and no cohesive tutorial. I have tried the following objects.
- Graphics. I can't create one linked to a memory bitmap.
- Image. Nope you can't create one of these either.
- PaintEventArgs you can create one but you can't use it.
- Bitmap Nope I cnt get it to work.
something MyPaintObject=new something(width, height, pixelformat); MyPaintObject.clear(color); MyPaintObject.fillrect();
...etc. Just regular paint commands
Then I want to be able to do this:
During a panel paint event: panel1.copyfrom(MyPaintObject);
...and when I want to save it, MyPaintObject.SaveToFile(filename, Bmp);
---
Ok, I got the answer: Here it is: thanks to a kind poster on the Microsoft forums.
Here's the Post: Graphics QuestionHere's the answer.
Bitmap myBitmap = new Bitmap(200, 200, PixelFormat.Format24bppRgb);
public void DrawBitmap()
{
using (Graphics myGraphics = Graphics.FromImage(myBitmap))
{
myGraphics.Clear(Color.AliceBlue);
Pen Bic = new Pen(Color.Blue);
myGraphics.DrawEllipse(Bic, new Rectangle(0, 0, 199, 199));
}
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
DrawBitmap();
e.Graphics.DrawImage(myBitmap, 0, 0);
}
No comments:
Post a Comment