1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| Imports System.Drawing
Public Class Form1
Public tmpBMP As Bitmap
Public cloBMP As Bitmap
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tmpBMP = New Bitmap(PictureBox1.Image)
cloBMP = New Bitmap(210, 210)
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Label1.Text = CStr(e.Location.X) + " - " + CStr(e.Location.Y)
Dim x As Int16 = e.Location.X - 105
Dim y As Int16 = e.Location.Y - 105
If x <= 0 Then x = 0
If y <= 0 Then y = 0
If x >= tmpBMP.Width Then x = tmpBMP.Width
If y >= tmpBMP.Height Then y = tmpBMP.Height
Dim rec As New Rectangle(x, y, 210, 210)
cloBMP = tmpBMP.Clone(rec, tmpBMP.PixelFormat)
Dim gra As Graphics = Graphics.FromImage(cloBMP)
gra.DrawLine(Pens.Red, 0, CInt(cloBMP.Height / 2), cloBMP.Width, CInt(cloBMP.Height / 2))
gra.DrawLine(Pens.Red, CInt(cloBMP.Width / 2), 0, CInt(cloBMP.Width / 2), cloBMP.Height)
gra.Dispose()
PictureBox2.Image = cloBMP
End Sub
End Class |
Partager