How to crop top image in asp.net c

You can download the dll files needed to use CropImage.Net from this link. Once you have a downloaded the files you need to add the dll files to your solution. You can follow the below steps to add the dlls.

  • Open your Project within the Solution Explorer
  • Right-click the References folder and Choose Add Reference options
  • Find and select the dlls which needs to be added to your solution
    • ImageResizer.dll
    • Imazen.Crop.dll
    • System.Web.Extensions.dll (You may need to use the browse button if you are not finding the dll in available list)
  • Click the Ok button to add it to your Project.

Now you have all the files added to your project

How to crop top image in asp.net c

Details of CropImage.Net Control:

CropImage.Net exposes method called Crop, which actually Crops the original image and saves it to the specified path. This method have two overrides one with destinationpath as parameter and another one with destinationpath and appendCorrectExtension.

public void Crop(string destPath);

public void Crop(string destPath, bool appendCorrectExtension) Implementation:

Here I am going to explain the steps on how to use CropImage.Net tool to crop the images using Asp.Net.

In this demo I will upload a file and then the uploaded file will be shown in an image control. Then with the help of CropImage control the image will be cropped and shown in another image control called result.

First Step is to register the ImageCrop control in your page like given below

<%@ Register Assembly="Imazen.Crop" Namespace="Imazen.Crop" TagPrefix="ic" %> Then you need add the below CropImage control to your page and then set it Image property to the Image control from which Image is used to crop.

Then we use the Crop method to crop and save the image to the destination path provided.

//Save the copy in local folder CropImage1.Crop(MapPath("~/images"), true); You also need to add the below configurations to your webconfig file

  
  
    
  
  
  
    
  
Complete Code:

HTML:

<%@ Register Assembly="Imazen.Crop" Namespace="Imazen.Crop" TagPrefix="ic" %>

  

Croping Image using ImageResizer in .Net

The result

C#:

protected void btnCrop_Click(object sender, EventArgs e)

{
    //Show the Result Image control   
    Result.Visible = true;  
    //Assign the image url from CropImage control  
    Result.ImageUrl = CropImage1.CroppedUrl;
    //Save the copy in local folder  
    CropImage1.Crop(MapPath("~/images"), true);
    //You can also get the coordinates from CropImage if you want to show to the user  
    this.Title = CropImage1.X + "," + CropImage1.Y + "," + CropImage1.X2 + "," + CropImage1.Y2;
}
protected void btnUpload_Click(object sender, EventArgs e)  
{  
    //Check if file upload is having any value  
    if (FileUpload1.HasFile)  
    {  
        try  
        {  
            //Get the uploaded filename from FileUpload Control  
            string filename = System.IO.Path.GetFileName(FileUpload1.FileName);  
            //Save the file to folder  
            FileUpload1.SaveAs(Server.MapPath("~/images/") + filename);  
            //Show the uploaded image in Image Control which is tagged to the Image Cropping Control  
            Image1.ImageUrl = "~/images/" + filename;  
        }  
        catch (Exception ex)  
        {  
            throw new Exception(ex.InnerException.ToString());  
        }  
    }  
}  
Note that I have used the folder which is inside in my solution.You can see that in the image given above. If you have a different you need to change the path accordingly.

Demo

How to crop top image in asp.net c

This entry was posted on May 18, 2015, 1:54 am and is filed under Asp.Net, C#, ThirdParty Tools. You can follow any responses to this entry through RSS 2.0. You can skip to the end and leave a response. Pinging is currently not allowed.

How to crop an image in asp net C#?

Write the code in btnCrop_Click event to crop & save cropped image..

// Crop Image Here & Save..

string fileName = Path.GetFileName(imgUpload.ImageUrl);.

string filePath = Path.Combine(Server.MapPath("~/UploadImages"), fileName);.

string cropFileName = "";.

string cropFilePath = "";.

if (File.Exists(filePath)) {.

How to resize an image in asp net C#?

Simple Image Resizing in C#.

First, load the image file using Image class..

Then, resize image by calling Image. Resize(Int32, Int32) method..

Finally, save resized image using Image. Save(string) method..

How to cut an image in C#?

C# Image Cropping using Rectangle.

First, load the image into a RasterImage object using Image. Load() method..

Then, cache the image..

Create a Rectangle object and initialize it with the desired size..

Pass the Rectangle object to RasterImage. Crop() method to crop the image..

Save the cropped image using RasterImage..