在VB.NET中,我需要基于已有的Graphics
对象创建一个Image
。但是没有Image.fromGraphics()
等方法,该怎么办呢?
发布于 2012-02-26 04:57:29
尝试像这样的MSDN article状态。本质上是从Bitmap
创建一个Graphics
对象。然后使用图形方法对Image
执行所需的操作,然后即可按需使用Image
。正如@Damien_The_Unbeliever所说的,创建图形对象是为了能够在另一个对象上绘图,它没有要复制的图像,而是创建它的对象。
来自上面的文章:
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
发布于 2012-02-26 05:21:23
看一看Graphics.DrawImage method及其重载。
下面是其中一个示例的代码片段,该示例使用来自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
https://stackoverflow.com/questions/9450591
复制相似问题