Graphics to Bitmap

  • Thread starter Thread starter Mathieu
  • Start date Start date
M

Mathieu

Hi !

How may I concert Graphics to Bitmap or Save Graphics to file...

// Dim g as Graphics
// g = pictureBox1.CreateGraphics
// g.Save ????

I Just want to Save g (Graphics) in file C:\g.bmp

Thank you !
 
There's no way to save the contents of the graphics object as a bitmap.
Graphics can be used to draw upon in memory bitmaps or on the screen but
it's a one way process. In order to capture the surface of the control or
perhaps the screen you need to use Interop to access the bitblt API from
unmanaged win32.

The GDI+ FAQ has an example of how to do this.

--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com
 
Mathieu,
You need to create a new Bitmap, get a graphics for the Bitmap, draw on this
graphics, then save the bitmap.

Something like:

Dim image As New Bitmap(100, 100)
Dim gr As Graphics = Graphics.FromImage(image)
gr.DrawRectangle(Pens.Blue, 10, 10, 80, 80)
gr.Dispose()
image.Save("C:\g.bmp")
image.Dispose()

Hope this helps
Jay
 
* "Mathieu said:
How may I concert Graphics to Bitmap or Save Graphics to file...

// Dim g as Graphics
// g = pictureBox1.CreateGraphics
// g.Save ????

I Just want to Save g (Graphics) in file C:\g.bmp

Draw onto a bitmap using its 'Graphics' object ('Graphics.FromImage').
Then dispose the 'Graphics' object and save the bitmap (by calling its
'Save' method).
 
Back
Top