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



Related .net document control helps:
asp.net display tiff images: ASP.NET Tiff Viewer: view, annotate multipage Tiff images in ASP.NET MVC, WebForms using C# Control
asp.net mvc pdf editor control: ASP.NET MVC PDF Viewer & Editor: view, annotate, redact, edit PDF document in C# ASP.NET MVC
asp.net image viewer jquery: ASP.NET Image Viewer Control(MVC & WebForms): view, annotate, redact, convert image files in html, JQuery
asp.net office document viewer: ASP.NET Office Word Document Viewer: view Word doc files online using C# in ASP.NET MVC web applications
asp.net pdf editor component: EdgePDF: ASP.NET PDF Editor Web Control: Online view, annotate, redact, edit, process, convert PDF documents
asp.net view text file: ASP.NET Text file viewer in MVC, WebForms: Open, view, annotate, convert txt files in C# ASP.NET
asp.net dicom web viewer: ASP.NET Dicom Document Viewer Control: view, annotate dicom imaging files online in ASP.NET


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");