MbahAgis

Image Crop

Jul 31st, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.10 KB | None | 0 0
  1. Public Class Form1
  2.     Private Sub BtnBrowse_Click(sender As Object, e As EventArgs) Handles BtnBrowse.Click
  3.         Using OFD As New OpenFileDialog()
  4.             With OFD
  5.                 .InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
  6.                 .FileName = Nothing
  7.                 .Multiselect = False
  8.                 .Title = "Pick an Image"
  9.                 .Filter = "Image files (*.jpg, , *.bmp, *.png) | *.jpg; *.bmp; *.png"
  10.                 If .ShowDialog = 1 Then
  11.                     PictureBox1.BackgroundImage = Image.FromFile(.FileName)
  12.                 End If
  13.             End With
  14.         End Using
  15.     End Sub
  16.  
  17.     Private Sub BtnCrop_Click(sender As Object, e As EventArgs) Handles BtnCrop.Click
  18.  
  19.         Using imageSource As New Bitmap(PictureBox1.BackgroundImage)
  20.             Dim imageTargetRect As Rectangle = New Rectangle(0, 0, 64, 64)
  21.             Dim cropImage As Bitmap = imageSource.Clone(imageTargetRect, PictureBox1.BackgroundImage.PixelFormat)
  22.             PictureBox2.BackgroundImage = cropImage
  23.         End Using
  24.  
  25.     End Sub
  26. End Class
  27.  
Advertisement
Add Comment
Please, Sign In to add comment