Guest User

Untitled

a guest
Feb 21st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.40 KB | None | 0 0
  1.     Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click, tsSave.Click
  2.         sfd1.FileName = "defaultFile"
  3.         sfd1.Filter = "Jpg (*.jpg)|*.jpg|BMP (*.bmp)|*.bmp|All Files (*.*)|*.*"
  4.         If sfd1.ShowDialog = Windows.Forms.DialogResult.OK Then
  5.             Console.WriteLine(sfd1.FileName)
  6.         End If
  7.  
  8.     End Sub
  9.  
  10.  
  11. #Region "Cropping"
  12.     Dim cropX As Integer
  13.     Dim cropY As Integer
  14.     Dim cropWidth As Integer
  15.     Dim cropHeight As Integer
  16.  
  17.     Dim oCropX As Integer
  18.     Dim oCropY As Integer
  19.     Dim cropBitmap As Bitmap
  20.  
  21.     Public cropPen As Pen
  22.     Public cropPenSize As Integer = 2
  23.     Public cropDashStyle As Drawing2D.DashStyle = Drawing2D.DashStyle.Solid
  24.     Public cropPenColor As Color = Color.Red
  25.  
  26.     Private Sub pictureHold_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pictureHold.MouseDown
  27.         Try
  28.             If e.Button = Windows.Forms.MouseButtons.Left Then
  29.  
  30.                 cropX = e.X
  31.                 cropY = e.Y
  32.  
  33.                 cropPen = New Pen(cropPenColor, cropPenSize)
  34.                 cropPen.DashStyle = DashStyle.DashDotDot
  35.                 Cursor = Cursors.Hand
  36.  
  37.             End If
  38.             pictureHold.Refresh()
  39.         Catch exc As Exception
  40.         End Try
  41.     End Sub
  42.     Dim tmppoint As Point
  43.     Private Sub pictureHold_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pictureHold.MouseMove
  44.  
  45.  
  46.         Try
  47.             If pictureHold.Image Is Nothing Then Exit Sub
  48.  
  49.             If e.Button = Windows.Forms.MouseButtons.Left Then
  50.  
  51.                 pictureHold.Refresh()
  52.                 cropWidth = e.X - cropX
  53.                 cropHeight = e.Y - cropY
  54.                 pictureHold.CreateGraphics.DrawRectangle(cropPen, cropX, cropY, cropWidth, cropHeight)
  55.             End If
  56.  
  57.  
  58.         Catch exc As Exception
  59.  
  60.             If Err.Number = 5 Then Exit Sub
  61.         End Try
  62.  
  63.     End Sub
  64.  
  65.     Private Sub pictureHold_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pictureHold.MouseUp
  66.  
  67.  
  68.         Try
  69.             Cursor = Cursors.Default
  70.             Try
  71.  
  72.                 If cropWidth < 1 Then
  73.                     Exit Sub
  74.                 End If
  75.  
  76.                 Dim rect As Rectangle = New Rectangle(cropX, cropY, cropWidth, cropHeight)
  77.                 Dim bit As Bitmap = New Bitmap(pictureHold.Image, pictureHold.Width, pictureHold.Height)
  78.  
  79.                 cropBitmap = New Bitmap(cropWidth, cropHeight)
  80.                 Dim g As Graphics = Graphics.FromImage(cropBitmap)
  81.                 g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
  82.                 g.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
  83.                 g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
  84.                 g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel)
  85.                 pbPrev.Image = cropBitmap
  86.  
  87.             Catch exc As Exception
  88.             End Try
  89.         Catch exc As Exception
  90.         End Try
  91.     End Sub
  92.  
  93.     Private Sub btnCrop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCrop.Click
  94.         If tmrSlide.Enabled = True Then
  95.             tmrSlide.Enabled = False
  96.         End If
  97.         pictureHold.Image = cropBitmap
  98.  
  99.  
  100.     End Sub
  101. #End Region
  102.  
  103. #Region "Brightness"
  104.     Private Sub tsBright_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsBright.Click
  105.         If btnBright.Visible = False Then
  106.             MessageBox.Show("Click the Bright Button Again To Remove Preview", "Cropping")
  107.             btnCrop.Visible = False
  108.             btnUndo.Visible = True
  109.             pbPrev.Visible = False
  110.             btnBright.Visible = True
  111.             pbBright.Visible = True
  112.             brightScroll.Visible = True
  113.         Else
  114.             brightScroll.Visible = False
  115.             btnCrop.Visible = False
  116.             btnUndo.Visible = False
  117.             pbBright.Visible = False
  118.             btnBright.Visible = False
  119.         End If
  120.  
  121.         pbBright.Image = pictureHold.Image
  122.  
  123.  
  124.         Dim r, g, b, height, width As Integer
  125.         Dim tempPicture As Bitmap = pbBright.Image
  126.         Dim colorOfPixel As Color
  127.         Dim brightness As Double
  128.         brightness = 1 + (0.01 * brightScroll.Value)
  129.  
  130.         height = tempPicture.Height - 1
  131.         width = tempPicture.Width - 1
  132.  
  133.         For x As Integer = 1 To width
  134.             For y As Integer = 1 To height
  135.                 colorOfPixel = tempPicture.GetPixel(x, y)
  136.  
  137.                 r = colorOfPixel.R * brightness
  138.                 g = colorOfPixel.G * brightness
  139.                 b = colorOfPixel.B * brightness
  140.  
  141.                 validateRGB(r, g, b)
  142.  
  143.                 tempPicture.SetPixel(x, y, Color.FromArgb(255, r, g, b))
  144.             Next
  145.         Next
  146.         pbBright.Image = tempPicture
  147.  
  148.     End Sub
  149.  
  150.     Private Sub validateRGB(ByVal r As Integer, ByVal g As Integer, ByVal b As Integer)
  151.         If r > 255 Or r < 0 Then
  152.             MessageBox.Show("Out Of Range, Resetting", "Out of range exception")
  153.         ElseIf g > 255 Or g < 0 Then
  154.             MessageBox.Show("Out Of Range, Resetting", "Out of range exception")
  155.         ElseIf b > 255 Or b < 0 Then
  156.             MessageBox.Show("Out Of Range, Resetting", "Out of range exception")
  157.         End If
  158.     End Sub
  159. #End Region
Add Comment
Please, Sign In to add comment