Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create graphic and save it as Bitmap

I have two questions:

1) I have a PictureBox and its Dock is set to Fill. When I resize the Form I cannot create a Graphic on the part of the PictureBox that is extended. What is the problem?

2) I want to convert the Graphic that is created on the PictureBox to Bitmap and save it as *.JPG or *.bmp. How can I do this?

like image 889
Hesam Qodsi Avatar asked May 21 '10 09:05

Hesam Qodsi


People also ask

How do I create a bitmap image?

You create them by taking pictures with a camera, capturing a desktop screenshot or saving a file in an image-editing program. Most image editors have an option to save files in BMP format, a lossless compression format similar to TIFF and appropriate for high-detail, offline work.

What is a bitmap C#?

A Bitmap is an object used to work with images defined by pixel data.


1 Answers

you can use the handle device to get the bitmap out of the picture box

Graphics g = pictureBox1.CreateGraphics();          
Bitmap bitMap = Bitmap.FromHbitmap(g.GetHdc());
bitMap.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);

or even better, if the pictureBox does`nt modify the image, you can directly get the image from the pictureBox control

pictureBox1.Image.Save("path", System.Drawing.Imaging.ImageFormat.Jpeg);
like image 143
Alex Pacurar Avatar answered Oct 20 '22 19:10

Alex Pacurar