vb.net 从图形创建图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9450591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create Image from Graphics
提问by Voldemort
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?
在 VB.NET 中,我需要Image
根据Graphics
我拥有的对象创建一个。但是,没有诸如此类的方法Image.fromGraphics()
。那我该怎么办?
回答by Mark Hall
Try something like this MSDN articlestates. 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.
尝试类似MSDN 文章所述的内容。本质上Graphics
从Bitmap
. 然后使用 Graphic 方法来做你需要做的事情Image
,然后你可以使用Image
你需要的方式。正如@Damien_The_Unbeliever 所说,您的图形对象是为了在另一个对象上绘图而创建的,它没有要复制的图像,它是在其上创建的对象。
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
回答by Jay Riggs
Have a look at the Graphics.DrawImage methodand its overloads.
查看Graphics.DrawImage 方法及其重载。
Here's a snippet from one of the examples that draws an image onto the screen, using a Graphics object from Winform's Paint event:
这是使用 Winform 的 Paint 事件中的 Graphics 对象将图像绘制到屏幕上的示例之一的片段:
Private Sub DrawImageRect(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create rectangle for displaying image.
Dim destRect As New Rectangle(100, 100, 450, 150)
' Draw image to screen.
e.Graphics.DrawImage(newImage, destRect)
End Sub