ARTICLE

How to Crop an image in VB.NET

Posted by Sapna Articles | Visual Basic Language December 21, 2010
In this article you will learn how to crop an image and create a new image with the cropped portion in VB.NET.
Download Files:
 
Reader Level:

This is article demonstrates that how to crop an image. Cropping provides the selection of a portion from the image and a new image will be created from the cropped portion. The code snippets provides a drag enabled and resizable rectangle to select the portion of the image to be cropped.

First of all load the picture box using this on the form to show by means of bitmap display method.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   Dim str As String = Application.StartupPath & "picture.gif"
   PreviewPictureBox.Image = System.Drawing.Bitmap.FromFile(str)
   crobPictureBox.Image = System.Drawing.Bitmap.FromFile(str)
End Sub

Now you can crop the image from the picture box using mouse move and mouse down events.

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim openDlg As New System.Windows.Forms.OpenFileDialog
   openDlg.Filter = "All Files"
   If openDlg.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
Exit
Sub
End
If
   If Not openDlg.FileName Is Nothing Then
     PreviewPictureBox.Image = System.Drawing.Bitmap.FromFile(openDlg.FileName)
     crobPictureBox.Image = System.Drawing.Bitmap.FromFile(openDlg.FileName)
   End If
End Sub


Image Cropping

CropImag.gif

I hope you will like this article.

Login to add your contents and source code to this article
share this article :
post comment
 

if you want crop any image, than i will suggest you to visit the link below http://www.raiseitsolutions.com/forum/viewtopic.php?f=4&t=2 if you visit this link, you will know how to crop an image easily thank you very much. :)

Posted by inzamam khan Jan 13, 2011
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor