从图形创建图像

Vol*_*ort 3 vb.net

在VB.NET中,我需要创建一个Image基于Graphics我拥有的对象.但是,没有诸如此类的方法Image.fromGraphics().那我该怎么办?

Mar*_*all 8

尝试这样的MSDN文章说明.Essentialy Graphics从a 创建一个Object Bitmap.然后使用Graphic方法执行您需要的操作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
Run Code Online (Sandbox Code Playgroud)