De todas maneras ya me senté y prefiero dejarlo como apoyo a demás gente. Disculpa el retraso.
Imports
System. Drawing. Drawing2D
Imports
System. Drawing. Imaging
Public
Class Form1
'
http://www.codeproject.com/KB/graphics/image_croppingVBNet.aspx" Honor al que se lo merece. Esto esta en codeproject. Yo lo que hice fue entenderlo y realmente aprender también.
'SizeMode = StretcImage
'Esto es importante si no lo colocas la imagen sale como descuadrada.
'Esto lo colocas en las propiedades del PictureBoxOrigen
Dim cropX As Integer = 0
Dim cropY As Integer = 0
Dim cropWidth As Integer = 0
Dim cropHeight As Integer = 0
Dim oCropX As Integer = 0
Dim oCropY As Integer = 0
Dim cropBitmap As Bitmap
Public cropPen As Pen
Public cropPenSize As Integer = 1 '2
Public cropDashStyle As Drawing2D.DashStyle = Drawing2D.DashStyle.Solid
Public cropPenColor As Color = Color.Yellow
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Try
If e.Button = Windows.Forms.MouseButtons.Left Then
cropX = e.X
cropY = e.Y
cropPen =
New Pen(cropPenColor, cropPenSize)
cropPen.DashStyle = DashStyle.DashDotDot
Cursor = Cursors.Cross
End If
PictureBox1.Refresh()
Catch exc As Exception
End Try
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Try
If PictureBox1.Image Is Nothing Then Exit Sub
If e.Button = Windows.Forms.MouseButtons.Left Then
PictureBox1.Refresh()
cropWidth = e.X - cropX
cropHeight = e.Y - cropY
PictureBox1.CreateGraphics.DrawRectangle(cropPen, cropX, cropY, cropWidth, cropHeight)
' Pinta un rectangulo
PictureBox1. CreateGraphics. FillRectangle(Brushes. RosyBrown, cropX, cropY, cropWidth, cropHeight)
' Pinta y llena el rectangulo
End If
Catch exc As Exception
If Err.Number = 5 Then Exit Sub
End Try
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
Try
Cursor = Cursors.Default
Try
If cropWidth < 1 Then
Exit Sub
End If
Dim rect As Rectangle = New Rectangle(cropX, cropY, cropWidth, cropHeight)
Dim bit As Bitmap = New Bitmap(PictureBox1.Image, PictureBox1.Width, PictureBox1.Height)
cropBitmap =
New Bitmap(cropWidth, cropHeight)
Dim g As Graphics = Graphics.FromImage(cropBitmap)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel)
PictureBox2.Image = cropBitmap
Catch exc As Exception
End Try
Catch exc As Exception
End Try
End Sub
End
Class