我将两个实心圆(形状)放在一个表格上,改变它们的颜色,然后移动它们。当我将它们放到正确的位置时,我想要捕获表单的全彩色图像并尽快将其放入数组中。我怎么能这样做?
以下是绘制对象的方法: 我在VB2010Express中从VB PowerPacks获得一个OvalShape并在表单上绘制一个圆圈。之后,我在代码中调整它:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OccultSize1 = 100
OccultSize2 = 50
OvalShape1.Width = OccultSize1
OvalShape1.Height = OccultSize1
OvalShape2.Width = OccultSize2
OvalShape2.Height = OccultSize2
OvalShape1.Left() = 155 - OvalShape1.Width / 2
OvalShape1.Top() = 153 - OvalShape1.Height / 2
OvalShape2.Left() = 155 - OvalShape2.Width / 2
OvalShape2.Top = 85 'temporary
OvalShape1.FillColor = Color.Yellow
OvalShape1.BorderColor = Color.Yellow
OvalShape2.FillColor = Color.Blue
OvalShape2.BorderColor = OvalShape2.FillColor
Label1.Text = "100"
Label2.Text = "50"
Label3.Text = "xxx"
tbHue.Value = OvalShape2.FillColor.GetHue
RadioButton1.Checked = False
RadioButton2.Checked = True
LineShape1.Visible = False
LineShape2.Visible = True
OvalShape3.Visible = False
End Sub
以下是我尝试使用DrawToBitmap(从Stack Overflow中复制了大部分内容):Button1.Click是我的补充。
Private Function GetFormImage(ByRef GetBitmap As String) As Bitmap
' Make the bitmap.
Dim wid As Integer = Me.Width
Dim hgt As Integer = Me.Height
Dim bm As New Bitmap(wid, hgt)
' Draw the form onto the bitmap.
Me.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
bm.Save("E:\rhtempsave\bm.bmp")
' Make a smaller bitmap without borders.
wid = 240 'Me.ClientSize.Width
hgt = 320 'Me.ClientSize.Height
Dim bm2 As New Bitmap(wid, hgt)
' Get the offset from the window's corner to its client
' area's corner.
Dim pt As New Point(0, 0)
pt = PointToScreen(pt)
Dim dx As Integer = 37 'pt.X - Me.Left
Dim dy As Integer = 10 'pt.Y - Me.Top
' Copy the part of the original bitmap that we want
' into the bitmap.
Dim gr As Graphics = Graphics.FromImage(bm2)
gr.DrawImage(bm, 0, 0, New Rectangle(dx, dy, wid, hgt), _
GraphicsUnit.Pixel)
bm2.Save("E:\rhtempsave\bm2.bmp")
Return bm2
End Function
答案 0 :(得分:0)
出于某种原因,今天我的磁盘上出现了位图,但不是昨天。在此期间我唯一做的就是关机并重启我的电脑。奇怪的是,这些bmps不能被Photoshop,Photoshop Elements或Win10的照片阅读器读取,但它们在磁盘文件对话框中显示为图标。可能是标题问题。我认为我很高兴下一步将bmp放入一个数组中以便以后检索。谢谢。我非常感谢你的迅速回应。