Select language
  1. Products
  2. Aspose.Imaging
  3. Crop
clearbit icon

Crop for .NET

Convenient tools to crop the image or photo, selecting the rectangular part. High efficiency crop is supported for various graphic formats.

Share
Instagram Logo Dribbble Logo Twitter Logo Youtube Logo

How to Crop Image File Using .NET Library

In order to crop Image file, we’ll use Aspose.Imaging for .NET API which is a feature-rich, powerful and easy to use image manipulation API for net platform. Open NuGet package manager, search for Aspose.Imaging and install. You may also use the following command from the Package Manager Console.

1
Install-Package Aspose.Imaging

Crop Image via .NET

You need Aspose.Imaging for .NET and Aspose.Imaging.Crop.NET license to try the code in your environment.

  1. Load the Image with an instance of specific Image class.
  2. Crop the image within specified rectangle
  3. Save or export image in the desired format, defined by the options
  4. Composite (multi page or multi frame) image crop is supported as well.

System Requirements

Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Core
  • Development environment like Visual Studio Code or Microsoft Visual Studio.
  • Aspose.Imaging for .NET DLL referenced in your project.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
 using Aspose.Imaging;

namespace CSharpTutorials
{
    class Program
    {
        static void Main(string[] args)
        {
            License license = new License();
            license.SetLicense("Aspose.Imaging.Resize.NET.lic");
            // This code decreases the size of the image twice 
            using (var image = (RasterImage)Image.Load("tiger0.png"))
            {
                image.Crop(new Rectangle(0, 0, image.Width >> 1, image.Height >> 1));

                image.Save("tiger0.jpg", new JpegOptions());
            }
        }
    }
}

You may find other allowed crop cases and examples here