Convert Images using C# Image Processing Library
Converting Images to Black n White and Grayscale
Sometimes you may require to convert colored images to Black n White or Grayscale for printing or archiving purposes. This article demonstrates the use of Aspose.Imaging for .NET API to achieve this using two methods as stated below.
- Binarization
- Grayscaling
Binarization
In order to understand the concept of Binarization, it is important to define a Binary Image; that is a digital image that can have only two possible values for each pixel. Normally, the two colors used for a binary image are black and white though any two colors can be used. Binarization is the process of converting an image to bi-level meaning that each pixel is stored as a single bit (0 or 1) where 0 denotes the absence of color and 1 means presence of color. Aspose.Imaging for .NET API currently supports two Binarization methods.
Binarization with Fixed Threshold
The following code snippet shows you how to use fixed threshold binarization can be applied to an image.
Binarization with Otsu Threshold
The following code snippet shows you how Otsu threshold binarization can be applied to an image.
Grayscaling
Gray-scaling is the process of converting a continuous-tone image to an image with discontinues gray shades. The following code snippet shows you how to use Grayscaling.
Convert Image to grayscale with Setting 16bit
Gray-scaling is the process of converting a continuous-tone image to an image with discontinues gray shades. The following code snippet shows you how to use Grayscaling with 16bits.
Convert GIF Image Layers To TIFF Image
Sometimes it is needed to extract and convert layers of a GIF Image into another raster image format to meet an application need. Aspose.Imaging API support the feature of extracting and converting layers of a GIF Image into another raster image formats. Firstly, we will create instance of image and load GIF image from the local disk, then we will get the total count of layers in the source image using Length property of GifFrameBlock class and iterate through the array of blocks. Now we will check if the block is NULL then ignore it else convert the block to TIFF image. The following code snippet shows you how to convert GIF image layers to TIFF image.
Converting SVG to Raster Format
See :
Converting Raster Image to PDF
See :
Converting Raster Image to Svg
See
Converting RGB color system to CMYK for Tiff file Format
Using Aspose.Imaging for .NET, developers can convert RGB color system file to CMYK tiff format. This article shows how to export/convert RGB color system file to CMYK tiff format with Aspose.Imaging. Using Aspose.Imaging for .NET you can load image of any format and than you can set various properties using TiffOptions class and save the image. The following code snippet shows you how to achieve this feature.
Working with animation
See
Converting Open document graphics
See
Converting Corel Draw images
See Convert CDR
Converting webp images
Converting eps images
Converting cmx images
Converting dicom images
Exporting Images
Along with a rich set of image processing routines, Aspose.Imaging provides specialized classes to convert images to other formats. Using this library, image format conversion is as simple as changing the file extension to desired format in the Image class Save method and by specifying the appropriate ImageOptions values. Below are some specialized classes for this purpose in ImageOptions namespace.
It is easy to export images with Aspose.Imaging for .NET API. All you need is an object of the appropriate class from ImageOptions namespace. By using these classes, you can easily export any image created, edited or simply loaded with Aspose.Imaging for .NET to any supported format. Below is an example that demonstrates this simple procedure. In the example, a GIF image is loaded by passing the file path as a parameter to the Load method. It is then exported to various image formats using the Save method. The examples here show how to load a GIF and save it to BMP, JPEG, PNG and finally TIFF using Aspose.Imaging for .NET with C# and Visual Basic.
Convert compressed vector formats
Aspose.Imaging supports next compressed vector formats: Emz(compressed emf), Wmz(compressed wmf), Svgz(compressed svg). Supported read of these formats and export to other formats.
Combining Images
This example uses Graphics class and shows how to combine two or more images into a single complete image.To demonstrate the operation, the example creates a new Image canvas in JPEG format and draw images on the canvas surface using Draw Image method exposed by Graphics class. Using Graphics class two or more images can be combine in such a way that the resultant image will look as a complete image with no space between the image parts and no pages. The canvas size must be equal to the size of resultant image. Following is the code demonstration that shows how to use Draw Image method of the Graphics class to combine images in a single image.
Expand and Crop Images
Aspose.Imaging API allows you to expand or crop an image during image conversion process. Developer needs to create a rectangle with X and Y coordinates and specify the width and height of the rectangle box. The X,Y and Width, Height of rectangle will depict the expansion or cropping of the loaded image. If it is required to expand or crop the image during image conversion, perform the following steps:
- Create an instance of RasterImage class and load the existing image.
- Create an Instance of ImageOption class.
- Create an instance of Rectangle class and initialize the X,Y and Width, Height of the rectangle
- Call Save method of the RasterImage class while passing output file name, image options and the rectangle object as parameters.
Read and Write XMP Data To Images
XMP (Extensible Metadata Platform) is an ISO standard. XMP standardizes a data model, a serialization format and core properties for the definition and processing of extensible metadata. It also provides guidelines for embedding XMP information into popular image such as JPEG, without breaking their readability by applications that do not support XMP. Using Aspose.Imaging for .NET API developers can read or write XMP metadata to images. This article demonstrates how XMP metadata can be read from image and write XMP metadata to images.
Create XMP Metadata, Write It And Read From File
The release of Aspose.Imaging for .NET 3.3.0 contains the Xmp namespace. With the help of Xmp namespace developer can create XMP metadata object and write it to an image. The following code snippet shows you how to use the XmpHeaderPi, XmpTrailerPi, XmpMeta, XmpPacketWrapper, PhotoshopPackage and DublinCorePackage packages contained in Xmp namespace.
Export Images in Multi Threaded Environment
Aspose.Imaging for .NET now supports converting images in multi threaded environment. Aspose.Imaging for .NET ensure the optimized performance of operations during execution of code in multi-threaded environment. All imaging option classes (e.g. BmpOptions, TiffOptions, JpegOptions, etc.) in the Aspose.Imaging for .NET now implement IDisposable interface. Therefore it is a must that developer properly dispose off the imaging options class object in case Source property is set. Following code snippet demonstrates the said functionality.
Aspose.Imaging now supports SyncRoot property while working in multi-threaded environment. Developer can use this property to synchronize access to the source stream. Following code snippet demonstrates how the SyncRoot property can be used.