|
|
C# Imaging Library
How to read, update image property information in C#?
With XImage.Raster, you can get, modify the image information in your C# ASP.NET, WinForms, WPF applications.
Once an image has been loaded in to an RasterImage object, information about the image is available through the properties and methods of the RasterImage object.
- PageCount: The count of the picture frames.
- Width: This parameter is an array used to record the width of each image frame, the unit is pixel.
- Height: This parameter is an array used to record the height of each image frame, the unit is pixel.
- HResolution: This parameter is a double array use to record horizontal resolution of each image frame, you can get the page by index starting at zero.
- VResolution: This parameter is a double array use to record vertical resolution of each image frame, you can get the page by index starting at zero.
- ColorSpace: This parameter is used to record color space, please refer to ColorSpace Site.
- Compression: The compression method of the image, please refer to Compression Enumeration.
- Format: The format of the image.
How to read, modify TIFF, PNG, BMP raster image information using C#?
Image Color Space
After you have loaded an image file into RasterImage object, you can read the image color space information
through property ColorSpace in C# ASP.NET, Windows application.
RasterImage image = new RasterImage("C://input//raster-sample-image.png");
ColorSpace colorSpace = image.ColorSpace;
Change color space of the image
Using XImage.Raster C# Imaging library, you can customize the image color space, and apply the modification through class ImageProcess.
- Load a png image with color space
sRGB into a RasterImage object
- Create a new
ImageProcess instance with image object loaded.
- Change image to new color space
ColorSpace.GRAY, and apply modification through method TransformColorspace
- Print the image with new color space to file path
RasterImage image = new RasterImage("C://input//raster-sample-image.png");
ImageProcess process = new ImageProcess(image);
process.TransformColorspace(ColorSpace.GRAY);
image.Save("C://output//raster-sample-image-color-space-changed.png");
Compare the original image and image with color space changed.
| Original image
|
Color Space Changed
|
|
|
Using the following API, you can change the specified page's color space in multiple pages image file (such as TIFF, GIF).
public void TransformColorspace(ColorSpace colorSpace, int pageIndex);
Image Format
Get the loaded image format using property format in C# application.
RasterImage image = new RasterImage("C://input//raster-sample-image.png");
string imageFormat = image.format;
Image Compression
Using XImage.Raster C# Image library, you can get the loaded image compression format through property Compress
RasterImage image = new RasterImage("C://input//raster-sample-image.png");
Compression compress = image.Compress;
Get the selected page's compression method from a multiple page image file (tiff or gif).
public Compression GetCompressionType(int pageIndex);
Change the image compression type in C#
Change the existing image compression type using method ImageProcess.TransformCompression() in C# codes.
RasterImage image = new RasterImage("C://input//raster-sample-image.png");
ImageProcess process = new ImageProcess(image);
process.TransformCompression(Compression.JPEG);
image.Save("C://output//raster-sample-image-compression-changed.jpg");
Image Resolutions
Get image horizontal and vertical resolution (dpi) values from properties HResolution and VResolution
RasterImage image = new RasterImage("C://input//raster-sample-image.png");
double horizontalResolution = image.HResolution;
double verticalResolution = image.VResolution;
Change Image Resolutions
Using C# imaging SDK, you can modify the image resolution settings through method ImageProcess.TransformResolution()
RasterImage image = new RasterImage("C://input//raster-sample-image.png");
ImageProcess process = new ImageProcess(image);
process.TransformResolution(300, 300);
image.Save("C://output//raster-sample-image-resolution-changed.png");
Change selected page's resolution from multiple TIFF or GIF image file.
public void TransformResolution(int horiResolution, int vertResolution, int pageIndex);
Image Page Count
Get loaded multiple pages image (tiff or gif) pages count through property PageCount.
RasterImage image = new RasterImage("C://input//multi-page-tiff-sample.tiff");
int pageCount = image.PageCount;
Image Page Width and Height
Get the first page's width and height in pixel
RasterImage image = new RasterImage("C://input//multi-page-tiff-sample.tiff");
float width = image.Width;
float height = image.Height;
Get the second page's width and height in pixel using method
ImageProcess.GetImageWidth() and ImageProcess.GetImageHeight().
RasterImage image = new RasterImage("C://input//multi-page-tiff-sample.tiff");
ImageProcess process = new ImageProcess(image);
int width = process.GetImageWidth(1);
int height = process.GetImageHeight(1);
Clone, copy a RasterImage
Call method RasterImage.Clone() to get a copy of the loaded source image. Any changes on cloned image will not affect the source image.
Get the image file size on disk.
Using C# image library, you can get an image file size or specified image page size on disc in C# application.
- Use method
ImageProcess.GetDiskSize() to get the whole image file size on disc.
- Use method
ImageProcess.GetDiskSize(int pageIndex) to get the specified image page size on disc.
RasterImage image = new RasterImage("C://input//multi-page-tiff-sample.tiff");
ImageProcess process = new ImageProcess(image);
int imageFileSize = process.GetDiskSize();
int imagePageSize = process.GetDiskSize(1);
Enum ColorSpace
public enum ColorSpace
{
Undefined,
RGB,
GRAY,
Transparent,
OHTA,
Lab,
XYZ,
YCbCr,
YCC,
YIQ,
YPbPr,
YUV,
CMYK,
sRGB,
HSB,
HSL,
HWB,
Rec601Luma,
Rec601YCbCr,
Rec709Luma,
Rec709YCbCr,
Log,
CMY,
Luv,
HCL,
LCH,
LMS,
LCHab,
LCHuv,
scRGB,
HSI,
HSV,
HCLp,
YDbDr,
xyY
}
Enum Compression
public enum Compression
{
Undefined,
No,
BZip,
DXT1,
DXT3,
DXT5,
Fax,
Group4,
JPEG,
JPEG2000,
LosslessJPEG,
LZW,
RLE,
Zip,
ZipS,
Piz,
Pxr24,
B44,
B44A,
LZMA,
JBIG1,
JBIG2
}
|