Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a JPG from a Control?

Lets say I have a custom control (child of System.Windows.Forms.UserControl) such as a graph. Is there a way I can take the drawing I did on the control and just export the current graphical state of the control to a JPG file?

like image 900
Anthony Avatar asked Dec 06 '25 01:12

Anthony


1 Answers

It is possible. Basically you will need to ask the control to render itself to a Bitmap and then save the Bitmap as jpeg

See the documentation of Control.DrawToBitmap() method.

Bitmap bmp = [Control.DrawToBitmap();
            bmp.Save("", System.Drawing.Imaging.ImageFormat.Jpeg);
like image 113
gyurisc Avatar answered Dec 07 '25 13:12

gyurisc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!