Anthony
Anthony

Reputation: 9581

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?

Upvotes: 3

Views: 281

Answers (1)

gyurisc
gyurisc

Reputation: 11512

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);

Upvotes: 5

Related Questions