How to C#: Imaging
Using Imaging SDK for C#.NET
Winforms Controls
Image Load
Image Access and Modify
Geometry: Crop
Geometry: Crop
  |  
Home ›› XImage.Raster ›› C# Raster: Crop Image according to Specified Size

How to C#: Crop Image according to Specified Size


Guide for How to Crop Image




Steps to Crop image with specific Region



Load an image with RasterImage object.


Create an image processor with ImageProcess object.


Call the method CropImage of ImageProcess object to complete the task croping image.


Save the croped image to an image file on the disk.


If you want to have a try, please refer to the following steps.




Install XImage.Raster in C# Project



Add necessary references to your C#.NET project. Right-click the project and select "Add Reference..." to locate and add the following DLLs as project references;


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XImage.Raster.dll


Use corresponding namespaces;


  using RasterEdge.XImage.Raster;


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




Crop Image Size



By using the XImage.Raster SDK, you can crop the current image to the specified valid size.


Sample Code (crop current image to specified size):




RasterImage img = new RasterImage(@"C:\input.tif");
ImageProcess process = new ImageProcess(img);
//Crop the image to the specified size, X coordinate is 10, Y coordinate is 20, and the target size is 200x200.
process.CropImage(new Rectangle(10, 20, 200, 200));
//If the tiff image has multiple pages,
//it will only crop the second page of the input tif
process.CropImage(new Rectangle(10, 20, 200, 200), 1);
img.Save(@"C:\croped.tif");