Imports System.Data
Imports System.Data.OleDb
Public Class EditarImagen
'variables para el movimiento de la imagen
Dim Go As Boolean
Dim leftSet As Boolean
Dim TopSet As Boolean
Dim Holdleft As Integer
Dim holdTop As Integer
Dim offleft As Integer
Dim offTop As Integer
'rectangulo
Dim g As System.Drawing.Graphics
Dim seleccion As Rectangle
Dim down As Boolean
Dim cuadrodialogo As New OpenFileDialog
Dim mapaimagen As Bitmap
Dim seleccioncolor As Color = Color.DarkBlue
Dim borde As Integer = 2
Dim largopictu As Integer = 300
Dim anchopictu As Integer = 300
Dim valor1, valor2 As Integer
'variables para conexion a bd de listbox
Private Sub EditarImagen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
seleccion = New Rectangle(New Point(200, 100), New Size(500, 700))
End Sub
Private Sub ButtonZoomMenos(sender As Object, e As EventArgs) Handles Button1.Click
Button1.Text = "-"
Me.PictureBox1.Width -= 20%
Me.PictureBox1.Height -= 20%
End Sub
Private Sub ButtonZoomMas(sender As Object, e As EventArgs) Handles Button2.Click
Button2.Text = "+"
Me.PictureBox1.Width += 20%
Me.PictureBox1.Height += 20%
End Sub
Public Sub CargarImagen(ByVal Imagen As String)
Me.PictureBox1.ImageLocation = Imagen
Me.Refresh()
End Sub
Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
Go = False
leftSet = False
TopSet = False
End Sub
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
Go = True
End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If Go = True Then
Holdleft = (Control.MousePosition.X - Me.Left)
holdTop = (Control.MousePosition.Y - Me.Left)
If TopSet = False Then
offTop = holdTop - sender.Top
TopSet = True
End If
If leftSet = False Then
offleft = Holdleft - sender.Left
leftSet = True
End If
sender.Left = Holdleft - offleft
sender.Top = holdTop - offTop
End If
End Sub
Private Sub ScrollZoom(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseWheel
Dim scale As New SizeF(1, 1)
Dim scaleData As New SizeF(0.01, 0.01)
scale.Width = 1
scale.Height = 1
If e.Delta > 0 Then
scale += scaleData
ElseIf e.Delta < 0 Then
scale -= scaleData
End If
If e.Delta <> 0 Then
PictureBox1.Scale(scale)
End If
End Sub
Private Sub ButtonCancelar(sender As Object, e As EventArgs) Handles Button3.Click
Me.Close()
End Sub
'rectangulo
'se encarga de dar color al cuadro seleccionador
Function cambiar(ByVal colour As Color, ByVal value As Integer) As Color
Dim c As Color
c = (Color.FromArgb((value), (colour)))
Return (c)
End Function
Private Sub ButtonGuardar(sender As Object, e As EventArgs) Handles Button4.Click
GuardarArchivoFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
GuardarArchivoFD.FileName = "Save Image"
GuardarArchivoFD.Filter = "JPEG|*.jpeg"
If GuardarArchivoFD.ShowDialog() <> DialogResult.Cancel Then
Dim savePath As String = GuardarArchivoFD.FileName
Dim bmp As Bitmap = New Bitmap(PictureBox1.Image)
bmp.Save(savePath, Imaging.ImageFormat.Jpeg)
End If
End Sub
Private Sub ButtonRotar(sender As Object, e As EventArgs) Handles Button6.Click
If PictureBox1.Image IsNot Nothing Then
Dim bmp As Bitmap = New Bitmap(PictureBox1.Image)
bmp.RotateFlip(RotateFlipType.Rotate90FlipNone)
PictureBox1.Image = bmp
Else
End If
End Sub
Private Sub ButtonCortar(sender As Object, e As EventArgs) Handles Button5.Click
'cortarimagen(mapaimagen).Save("C:\Users\alanr\Desktop\pruebas\resultado", Imaging.ImageFormat.Png)
Dim cortado As Bitmap = New Bitmap(PictureBox1.Image)
Dim cloneImage As Bitmap = cortado.Clone(seleccion, System.Drawing.Imaging.PixelFormat.DontCare)
PictureBox1.Image = cloneImage
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.FillRectangle((New SolidBrush((cambiar((seleccioncolor), 100)))), seleccion)
e.Graphics.DrawRectangle((New Pen((New SolidBrush((seleccioncolor))), borde)), seleccion)
e.Graphics.DrawString(seleccion.Width & "x" & seleccion.Height, New Font("Arial", 10, FontStyle.Regular), Brushes.White, New Point(200, 100))
End Sub
End Class