Vb.net 关于在Visual Basic中绘制上载图像的可移动矩形
在VB 2010中,我一直在研究一个可移动的矩形来计算图像的ROI,因为我是VB新手,所以我能够创建一个矩形,但它不会出现在我上传的图像上。它会出现,但不会出现在图像上。根据我下面列出的代码 1.如何获得要在图像上显示的矩形。 2.如何使矩形在图像中变为可移动的。我将不胜感激。谢谢Vb.net 关于在Visual Basic中绘制上载图像的可移动矩形,vb.net,image-processing,Vb.net,Image Processing,在VB 2010中,我一直在研究一个可移动的矩形来计算图像的ROI,因为我是VB新手,所以我能够创建一个矩形,但它不会出现在我上传的图像上。它会出现,但不会出现在图像上。根据我下面列出的代码 1.如何获得要在图像上显示的矩形。 2.如何使矩形在图像中变为可移动的。我将不胜感激。谢谢 Private Sub ROIToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ROIToolStrip
Private Sub ROIToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ROIToolStripMenuItem.Click
Dim G As Graphics
G = PictureBox1.CreateGraphics
G.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
G.FillRectangle(Brushes.Silver, ClientRectangle)
Dim P As Point
Dim Box As Rectangle
P.X = 1
P.Y = 1
Dim S As Size
S.Width = 100
S.Height = 20
Box = New Rectangle(P, S)
G.DrawRectangle(Pens.Red, Box)
请尝试下面的代码
Dim G As Graphics
Dim uploadedBmp1, backgroundBmp1 As Bitmap
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
uploadedBmp1 = New Bitmap("C:\Windows\winnt.bmp")
backgroundBmp1 = New Bitmap(uploadedBmp1.Width, uploadedBmp1.Height)
G = Graphics.FromImage(backgroundBmp1)
PictureBox1.Image = backgroundBmp1
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
DrawRectangleOnImage(New Point(0, 0), New Size(100, 50))
End Sub
Private Sub DrawRectangleOnImage(ByVal point1 As Point, ByVal size1 As Size)
G.Clear(Color.White)
G.DrawImage(uploadedBmp1, 0, 0, uploadedBmp1.Width, uploadedBmp1.Height)
Dim rectangle1 As New Rectangle(point1, size1)
G.DrawRectangle(Pens.Red, rectangle1)
PictureBox1.Invalidate()
End Sub
要制作一个移动的矩形,只需使用所需的参数调用DrawRectangleOnImageSub。它将自动清除上一个快照并再次绘制所有内容