User Guide > How to Work with... > Images and ImGearPage |
One of the primary entities in the ImageGear for .NET toolkit is page and its implementation as ImGearPage Class.
ImGearPage Class consists of three main parts: image data, metadata, and region of interest.
Image data (or simply, image) is available for manipulations through the DIB property and is a ImGearDIB Class type. Color space, channels, width, and height are major attributes which define image structure.
ImageGear for .NET considers an image as a collection of channels, each of which gives some single piece of information about the pixels in a whole image. Channels are defined as an array of depths for each channel. Depth specifies the quantity of different values for a particular channel. This data is constant for the page until image processing functions are applied. It may be accessed through the ImGearDIB.ChannelDepths Property.
The ImGearColorSpace Structure (returned by the ImGearDIB.ColorSpace Property) defines the semantics of the information stored in all channels (i.e., whether the second channel is the green component of RGB color, magenta of CMYK, or alpha value of a grayscale image). This information may be formed from ImGearColorSpaceIDs Enumeration flags and placed into the constructor of ImGearPage Class.
Pixels in ImGearDIB Class may be accessed as both individual pixels or groups of pixels. GetPixelCopy Method() and UpdateColumnFrom Method() are examples of such members. An important issue is that all of these routines return copies of the data stored in an image as an array of the ImGearPixel Class. None of these members allows direct access to the pixel store.
To gain direct access to an image, GetImage Method() or GetRaster Method() members of ImGearDIB Class should be used. This is an efficient way to implement image processing routines, since all changes made to the structures (returned by these functions) will be reflected in the image. Users of GetImage Method() or GetRaster Method() should completely understand the structure of the internal pixel store to avoid producing ill-formed images.
The following example creates an RGB image and swaps red and blue channel values for diagonal pixels.
C# |
Copy Code |
---|---|
const int pageSize = 200; const int redChannel = 0; const int greenChannel = 1; const int blueChannel = 2; // Creates page with RGB colorspace and 8 bits channels. ImGearPage igPage = new ImGearRasterPage(pageSize, pageSize, new ImGearColorSpace(ImGearColorSpaceIDs.RGB), new int[] { 8, 8, 8 }, true); // Iterates all rows in created page. for (int row = 0; row < igPage.DIB.Height; ++row) { // Obtains reference to raster store. ImGearArrayRef igArrayRef = igPage.DIB.GetRaster(row); // Casts content to byte[] since all channels are 8 bit. byte[] raster = (byte[])igArrayRef.Content; // Offset of diagonal pixel in raster. int pixelOffset = igArrayRef.Offset + row * igPage.DIB.ChannelCount; // Swaps red & blue. byte red = raster[pixelOffset + redChannel]; raster[pixelOffset + redChannel] = raster[pixelOffset + blueChannel]; raster[pixelOffset + blueChannel] = red; } |
Metadata is non-image data, often available in some complex formats like TIFF or PNG. It may have complexity and is completely dependent on the nature of the file format. To provide a way of manipulating such data, ImageGear for .NET offers a set of classes composed from ImGearMetadataNode Class, ImGearMetadataNodeList Class and ImGearMetadataTree Class and their descendants. For a particular ImGearPage Class instance, metadata may be accessed through the Metadata Property.
Region of interest (ImGearROI Class) represents a free-shape image area (rectangular, non-rectangluar, or entire space) and specifies a meaningful part of an image. For example, a region of interest may be established to define an area where some image processing functions should be applied.