从图形创建图像 [英] Create Image from Graphics
问题描述
在 VB.NET 中,我需要基于我拥有的 Graphics
对象创建一个 Image
.但是没有Image.fromGraphics()
等方法,那我该怎么办?
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?
推荐答案
试试这样的MSDN文章 状态.本质上是从 Bitmap
创建一个 Graphics
对象.然后使用 Graphic 方法对 Image
执行您需要的操作,然后您可以根据需要使用 Image
.正如@Damien_The_Unbeliever 所说,您的图形对象是为了在另一个对象上绘图而创建的,它没有要复制的图像,而创建它的对象却有.
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.
来自以上文章:
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
这篇关于从图形创建图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!