Using ImageCropper

  1. Download the control and install it.
  2. Add a reference to the ImageCropper.dll file found in the ~/bin directory of the application you installed it to.
  3. After adding the ImageCropper control to the toolbox (as described here) drag it to the page.
  4. Set properties in the Property Box.
  5. Optionaly set properties and otherwise manipulate the control in the code-behind file.
  6. Handle the ImageCropped event, saving the cropped image to a file, session variable, database, etc.

Example Code

Within the aspx file:

<form id="Form1" method="post" runat="server">
    <cc1:imagecropper id="ImageCropper1" runat="server" ImageUrl="/images/uncropped.jpg">
    </cc1:imagecropper>
    <asp:Button Runat="server" Text="Crop"></asp:Button>
</form>

Within the code-behind file:

C#
private void InitializeComponent() { this.ImageCropper1.ImageCropped += new System.EventHandler(this.ImageCropper1_ImageCropped); this.Load += new System.EventHandler(this.Page_Load); } private void ImageCropper1_ImageCropped(object sender, System.EventArgs e) { Bitmap croppedImage = ImageCropper1.CroppedImage; croppedImage.Save(Server.MapPath("/images/cropped.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg); croppedImage.Dispose(); }
VB.NET
Private Sub ImageCropper1_ImageCropped(ByVal sender As Object, ByVal e As System.EventArgs) Handles ImageCropper1.ImageCropped Dim croppedImage As Bitmap = ImageCropper1.CroppedImage croppedImage.Save(Server.MapPath("/images/cropped.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg) croppedImage.Dispose() End Sub