//pnl is the panel you have Bitmap bmp = new Bitmap(pnl.Bounds.Width, pnl.Bounds.Height); pnl.DrawToBitmap(bmp, pnl.Bounds); bmp.Save("C:\\myimage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
Hello, thank you for the fast reply.
This seems to be returning something weird.
The panel looks like this: [url]http://users.telenet.be/seti2k/panel.jpg[/url]
The saved image like this: [url]http://users.telenet.be/seti2k/myimage.jpg[/url]
thanks in advance.
Muster's code looks OK to me but I do know that the DrawToBitmap method can't cope with RichTextBoxes and Active X controls. Do you have either of those in your panel?
If you're just drawing on the panel then I don't understand why the previous code doesn't work properly but see if it's any better if you do it a different way:
Bitmap bmp = new Bitmap(pnl.Bounds.Width, pnl.Bounds.Height); Graphics gfx = Graphics.FromImage(bmp); gfx.CopyFromScreen(this.PointToScreen(pnl.Bounds.Location), new Point(0, 0), pnl.Bounds.Size); bmp.Save("C:\\myimage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); gfx.Dispose(); bmp.Dispose();
That's true though, if DrawToBitmap doesn't work, I don't know what else to suggest unless you create and draw to the bitmap at the same time as you draw to the panel. Could you momentarily make the panel or tab visible whilst you do the screen copy and then change it back or would this be too jerky?
I must be doing something wrong with the painting itself, I made a new project with just this in it. The stuff is coming on the panel, so I see the red circle & line, but the result looks like this when I save: http://users.telenet.be/seti2k/myimage.jpg
namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
The DrawToBitmap method will only persist something that's been drawn in the panel's Paint eventhandler using the graphics object provided by the argument, e, to that handler.
So, I'd try instead:
namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
4 answers
maybe you can try something like this
answered one year ago by:
1556
30
Hello, thank you for the fast reply. This seems to be returning something weird. The panel looks like this: [url]http://users.telenet.be/seti2k/panel.jpg[/url] The saved image like this: [url]http://users.telenet.be/seti2k/myimage.jpg[/url] thanks in advance.
17279
Muster's code looks OK to me but I do know that the DrawToBitmap method can't cope with RichTextBoxes and Active X controls. Do you have either of those in your panel?
30
Not really, the only thing that is on that panel are graphics (drawstring, drawimage, drawline, etc) , it's really weird this thingie :|
If you're just drawing on the panel then I don't understand why the previous code doesn't work properly but see if it's any better if you do it a different way:
answered one year ago by:
17279
30
I have no idea why. Your last code works, but that's more taking a "screenshot", so if my panel is hidden or on another tab this won't work.
17279
That's true though, if DrawToBitmap doesn't work, I don't know what else to suggest unless you create and draw to the bitmap at the same time as you draw to the panel. Could you momentarily make the panel or tab visible whilst you do the screen copy and then change it back or would this be too jerky?
I must be doing something wrong with the painting itself, I made a new project with just this in it.
The stuff is coming on the panel, so I see the red circle & line, but the result looks like this when I save: http://users.telenet.be/seti2k/myimage.jpg
answered one year ago by:
30
I think the problem here is graphics persistence.
The DrawToBitmap method will only persist something that's been drawn in the panel's Paint eventhandler using the graphics object provided by the argument, e, to that handler.
So, I'd try instead:
answered one year ago by:
17279
30
Ok thank you all, this seems to work fine!