Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Image from Graphics

Tags:

vb.net

In VB.NET, I need to create an Image based on a Graphics object I have. However, there is no method such as Image.fromGraphics() etc. What should I do then?

like image 922
Voldemort Avatar asked Jan 17 '23 09:01

Voldemort


1 Answers

Try something like this MSDN article states. Essentialy create a Graphics Object from a Bitmap. Then use Graphic methods to do what you need to to the Image and then you can use the Image how you need to. As @Damien_The_Unbeliever stated your Graphics Object is created to enable drawing on another object, it does not have an Image to copy, the object it was created on does.

From above article:

Dim flag As New Bitmap(200, 100)
Dim flagGraphics As Graphics = Graphics.FromImage(flag)
Dim red As Integer = 0
Dim white As Integer = 11
While white <= 100
    flagGraphics.FillRectangle(Brushes.Red, 0, red, 200, 10)
    flagGraphics.FillRectangle(Brushes.White, 0, white, 200, 10)
    red += 20
    white += 20
End While
pictureBox1.Image = flag
like image 95
Mark Hall Avatar answered Feb 24 '23 14:02

Mark Hall