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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With