Class RasterImage
Represents a raster image supporting raster graphics operations.
public abstract class RasterImage : Image, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata
- Inheritance
-
RasterImage
- Implements
- Derived
- Inherited Members
Constructors
RasterImage()
Initializes a new instance of the RasterImage class.
protected RasterImage()
RasterImage(IColorPalette)
Initializes a new instance of the RasterImage class.
protected RasterImage(IColorPalette colorPalette)
Parameters
colorPalette
IColorPaletteThe color palette.
Fields
xmpData
The XMP metadata
protected XmpPacketWrapper xmpData
Field Value
Properties
DataLoader
Gets or sets the data loader.
protected IRasterImageArgb32PixelLoader DataLoader { get; set; }
Property Value
- IRasterImageArgb32PixelLoader
The data loader.
HasAlpha
Gets a value indicating whether this instance has alpha.
public virtual bool HasAlpha { get; }
Property Value
- bool
true
if this instance has alpha; otherwise,false
.
HasTransparentColor
Gets a value indicating whether image has transparent color.
public virtual bool HasTransparentColor { get; set; }
Property Value
HorizontalResolution
Gets or sets the horizontal resolution, in pixels per inch, of this RasterImage.
public virtual double HorizontalResolution { get; set; }
Property Value
- double
The horizontal resolution.
Remarks
Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.
ImageOpacity
Gets opacity of this image.
public virtual float ImageOpacity { get; }
Property Value
- float
The opacity value between 0.0 (fully transparent) and 1.0 (fully opaque).
IsRawDataAvailable
Gets a value indicating whether raw data loading is available.
public bool IsRawDataAvailable { get; }
Property Value
- bool
true
if this raw data loading is available; otherwise,false
.
PremultiplyComponents
Gets or sets a value indicating whether the image components must be premultiplied.
public virtual bool PremultiplyComponents { get; set; }
Property Value
- bool
true
if the image components must be premultiplied; otherwise,false
.
RawCustomColorConverter
Gets or sets the custom color converter
public IColorConverter RawCustomColorConverter { get; set; }
Property Value
- IColorConverter
The custom color converter
RawDataFormat
Gets the raw data format.
public virtual PixelDataFormat RawDataFormat { get; }
Property Value
- PixelDataFormat
The raw data format.
RawDataSettings
Gets the current raw data settings. Note when using these settings the data loads without conversion.
public RawDataSettings RawDataSettings { get; }
Property Value
- RawDataSettings
The current raw data settings.
RawFallbackIndex
Gets or sets the fallback index to use when palette index is out of bounds
public int RawFallbackIndex { get; set; }
Property Value
- int
The fallback index to use when palette index is out of bounds
RawIndexedColorConverter
Gets or sets the indexed color converter
public IIndexedColorConverter RawIndexedColorConverter { get; set; }
Property Value
- IIndexedColorConverter
The indexed color converter
RawLineSize
Gets the raw line size in bytes.
public virtual int RawLineSize { get; }
Property Value
- int
The raw line size in bytes.
TransparentColor
Gets the image transparent color.
public virtual Color TransparentColor { get; set; }
Property Value
UpdateXmpData
Gets or sets a value indicating whether to update the XMP metadata.
public virtual bool UpdateXmpData { get; set; }
Property Value
- bool
true
if update the XMP metadata; otherwise,false
.
UsePalette
Gets a value indicating whether the image palette is used.
public override bool UsePalette { get; }
Property Value
- bool
true
if the palette is used in the image; otherwise,false
.
UseRawData
Gets or sets a value indicating whether to use raw data loading when the raw data loading is available.
public virtual bool UseRawData { get; set; }
Property Value
- bool
true
if use raw data loading when the raw data loading is available.; otherwise,false
.
VerticalResolution
Gets or sets the vertical resolution, in pixels per inch, of this RasterImage.
public virtual double VerticalResolution { get; set; }
Property Value
- double
The vertical resolution.
Remarks
Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.
XmpData
Gets or sets the XMP metadata.
public virtual XmpPacketWrapper XmpData { get; set; }
Property Value
- XmpPacketWrapper
The XMP metadata.
Methods
AdjustBrightness(int)
Adjust of a brightness for image.
public virtual void AdjustBrightness(int brightness)
Parameters
brightness
intBrightness value.
AdjustContrast(float)
Image contrasting
public virtual void AdjustContrast(float contrast)
Parameters
contrast
floatContrast value (in range [-100; 100])
AdjustGamma(float)
Gamma-correction of an image.
public virtual void AdjustGamma(float gamma)
Parameters
gamma
floatGamma for red, green and blue channels coefficient
AdjustGamma(float, float, float)
Gamma-correction of an image.
public virtual void AdjustGamma(float gammaRed, float gammaGreen, float gammaBlue)
Parameters
gammaRed
floatGamma for red channel coefficient
gammaGreen
floatGamma for green channel coefficient
gammaBlue
floatGamma for blue channel coefficient
BinarizeBradley(double)
Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding
public virtual void BinarizeBradley(double brightnessDifference)
Parameters
brightnessDifference
doubleThe brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
BinarizeBradley(double, int)
Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding
public virtual void BinarizeBradley(double brightnessDifference, int windowSize)
Parameters
brightnessDifference
doubleThe brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
windowSize
intThe size of s x s window of pixels centered around this pixel
BinarizeFixed(byte)
Binarization of an image with predefined threshold
public virtual void BinarizeFixed(byte threshold)
Parameters
threshold
byteThreshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.
BinarizeOtsu()
Binarization of an image with Otsu thresholding
public virtual void BinarizeOtsu()
Blend(Point, RasterImage, Rectangle, byte)
Blends this image instance with the overlay
image.
public virtual void Blend(Point origin, RasterImage overlay, Rectangle overlayArea, byte overlayAlpha = 255)
Parameters
origin
PointThe background image blending origin.
overlay
RasterImageThe overlay image.
overlayArea
RectangleThe overlay area.
overlayAlpha
byteThe overlay alpha.
Blend(Point, RasterImage, byte)
Blends this image instance with the overlay
image.
public void Blend(Point origin, RasterImage overlay, byte overlayAlpha = 255)
Parameters
origin
PointThe background image blending origin.
overlay
RasterImageThe overlay image.
overlayAlpha
byteThe overlay alpha.
Crop(Rectangle)
Crops the specified rectangle.
public virtual void Crop(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle.
Crop(int, int, int, int)
Crop image with shifts.
public virtual void Crop(int leftShift, int rightShift, int topShift, int bottomShift)
Parameters
leftShift
intThe left shift.
rightShift
intThe right shift.
topShift
intThe top shift.
bottomShift
intThe bottom shift.
Dither(DitheringMethod, int)
Performs dithering on the current image.
public void Dither(DitheringMethod ditheringMethod, int bitsCount)
Parameters
ditheringMethod
DitheringMethodThe dithering method.
bitsCount
intThe final bits count for dithering.
Dither(DitheringMethod, int, IColorPalette)
Performs dithering on the current image.
public abstract void Dither(DitheringMethod ditheringMethod, int bitsCount, IColorPalette customPalette)
Parameters
ditheringMethod
DitheringMethodThe dithering method.
bitsCount
intThe final bits count for dithering.
customPalette
IColorPaletteThe custom palette for dithering.
Filter(Rectangle, FilterOptionsBase)
Filters the specified rectangle.
public virtual void Filter(Rectangle rectangle, FilterOptionsBase options)
Parameters
rectangle
RectangleThe rectangle.
options
FilterOptionsBaseThe options.
GetArgb32Pixel(int, int)
Gets an image 32-bit ARGB pixel.
public int GetArgb32Pixel(int x, int y)
Parameters
Returns
- int
The 32-bit ARGB pixel for the specified location.
GetDefaultArgb32Pixels(Rectangle)
Gets the default 32-bit ARGB pixels array.
public int[] GetDefaultArgb32Pixels(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle to get pixels for.
Returns
- int[]
The default pixels array.
GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader)
Gets the default pixels array using partial pixel loader.
public void GetDefaultPixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)
Parameters
rectangle
RectangleThe rectangle to get pixels for.
partialPixelLoader
IPartialArgb32PixelLoaderThe partial pixel loader.
GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings)
Gets the default raw data array using partial pixel loader.
public void GetDefaultRawData(Rectangle rectangle, IPartialRawDataLoader partialRawDataLoader, RawDataSettings rawDataSettings)
Parameters
rectangle
RectangleThe rectangle to get pixels for.
partialRawDataLoader
IPartialRawDataLoaderThe partial raw data loader.
rawDataSettings
RawDataSettingsThe raw data settings.
GetDefaultRawData(Rectangle, RawDataSettings)
Gets the default raw data array.
public byte[] GetDefaultRawData(Rectangle rectangle, RawDataSettings rawDataSettings)
Parameters
rectangle
RectangleThe rectangle to get raw data for.
rawDataSettings
RawDataSettingsThe raw data settings.
Returns
- byte[]
The default raw data array.
GetModifyDate(bool)
Gets the date and time the resource image was last modified.
public virtual DateTime GetModifyDate(bool useDefault)
Parameters
useDefault
boolif set to
true
uses the information from FileInfo as default value.
Returns
- DateTime
The date and time the resource image was last modified.
GetPixel(int, int)
Gets an image pixel.
public Color GetPixel(int x, int y)
Parameters
Returns
- Color
The pixel color for the specified location.
GetSkewAngle()
Gets the skew angle. This method is applicable to scanned text documents, to determine the skew angle when scanning.
public float GetSkewAngle()
Returns
- float
The skew angle, in degrees.
Grayscale()
Transformation of an image to its grayscale representation
public virtual void Grayscale()
LoadArgb32Pixels(Rectangle)
Loads 32-bit ARGB pixels.
public int[] LoadArgb32Pixels(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle to load pixels from.
Returns
- int[]
The loaded 32-bit ARGB pixels array.
LoadArgb64Pixels(Rectangle)
Loads 64-bit ARGB pixels.
public long[] LoadArgb64Pixels(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle to load pixels from.
Returns
- long[]
The loaded 64-bit ARGB pixels array.
LoadCmyk32Pixels(Rectangle)
Loads pixels in CMYK format.
public int[] LoadCmyk32Pixels(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle to load pixels from.
Returns
- int[]
The loaded CMYK pixels presentes as 32-bit inateger values.
LoadCmykPixels(Rectangle)
Loads pixels in CMYK format. This method is deprecated. Please use more effective the LoadCmyk32Pixels(Rectangle) method.
[Obsolete("Method is obsolete")]
public CmykColor[] LoadCmykPixels(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle to load pixels from.
Returns
- CmykColor
The loaded CMYK pixels array.
LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader)
Loads 32-bit ARGB pixels partially by packs.
public void LoadPartialArgb32Pixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)
Parameters
rectangle
RectangleThe desired rectangle.
partialPixelLoader
IPartialArgb32PixelLoaderThe 32-bit ARGB pixel loader.
LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader)
Loads 64-bit ARGB pixels partially by packs.
public void LoadPartialArgb64Pixels(Rectangle rectangle, IPartialArgb64PixelLoader partialPixelLoader)
Parameters
rectangle
RectangleThe desired rectangle.
partialPixelLoader
IPartialArgb64PixelLoaderThe 64-bit ARGB pixel loader.
LoadPartialPixels(Rectangle, IPartialPixelLoader)
Loads pixels partially by packs.
public void LoadPartialPixels(Rectangle desiredRectangle, IPartialPixelLoader pixelLoader)
Parameters
desiredRectangle
RectangleThe desired rectangle.
pixelLoader
IPartialPixelLoaderThe pixel loader.
LoadPixels(Rectangle)
Loads pixels.
public Color[] LoadPixels(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle to load pixels from.
Returns
- Color[]
The loaded pixels array.
LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader)
Loads raw data.
public void LoadRawData(Rectangle rectangle, RawDataSettings rawDataSettings, IPartialRawDataLoader rawDataLoader)
Parameters
rectangle
RectangleThe rectangle to load raw data from.
rawDataSettings
RawDataSettingsThe raw data settings to use for loaded data. Note if data is not in the format specified then data conversion will be performed.
rawDataLoader
IPartialRawDataLoaderThe raw data loader.
LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader)
Loads raw data.
public void LoadRawData(Rectangle rectangle, Rectangle destImageBounds, RawDataSettings rawDataSettings, IPartialRawDataLoader rawDataLoader)
Parameters
rectangle
RectangleThe rectangle to load raw data from.
destImageBounds
RectangleThe dest image bounds.
rawDataSettings
RawDataSettingsThe raw data settings to use for loaded data. Note if data is not in the format specified then data conversion will be performed.
rawDataLoader
IPartialRawDataLoaderThe raw data loader.
NormalizeAngle()
Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses GetSkewAngle() and Rotate(float) methods.
public void NormalizeAngle()
NormalizeAngle(bool, Color)
Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses GetSkewAngle() and Rotate(float, bool, Color) methods.
public virtual void NormalizeAngle(bool resizeProportionally, Color backgroundColor)
Parameters
resizeProportionally
boolif set to
true
you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.backgroundColor
ColorColor of the background.
ReadArgb32ScanLine(int)
Reads the whole scan line by the specified scan line index.
public int[] ReadArgb32ScanLine(int scanLineIndex)
Parameters
scanLineIndex
intZero based index of the scan line.
Returns
- int[]
The scan line 32-bit ARGB color values array.
ReadScanLine(int)
Reads the whole scan line by the specified scan line index.
public Color[] ReadScanLine(int scanLineIndex)
Parameters
scanLineIndex
intZero based index of the scan line.
Returns
- Color[]
The scan line pixel color values array.
ReleaseManagedResources()
Releases the managed resources. Make sure no unmanaged resources are released here, since they may have been already released.
protected override void ReleaseManagedResources()
RemoveMetadata()
public override void RemoveMetadata()
ReplaceColor(Color, byte, Color)
Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
public void ReplaceColor(Color oldColor, byte oldColorDiff, Color newColor)
Parameters
oldColor
ColorOld color to be replaced.
oldColorDiff
byteAllowed difference in old color to be able to widen replaced color tone.
newColor
ColorNew color to replace old color with.
ReplaceColor(int, byte, int)
Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
public virtual void ReplaceColor(int oldColorArgb, byte oldColorDiff, int newColorArgb)
Parameters
oldColorArgb
intOld color ARGB value to be replaced.
oldColorDiff
byteAllowed difference in old color to be able to widen replaced color tone.
newColorArgb
intNew color ARGB value to replace old color with.
ReplaceNonTransparentColors(Color)
Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.
public void ReplaceNonTransparentColors(Color newColor)
Parameters
newColor
ColorNew color to replace non transparent colors with.
ReplaceNonTransparentColors(int)
Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.
public virtual void ReplaceNonTransparentColors(int newColorArgb)
Parameters
newColorArgb
intNew color ARGB value to replace non transparent colors with.
Resize(int, int, ImageResizeSettings)
Resizes the image with extended options.
public override void Resize(int newWidth, int newHeight, ImageResizeSettings settings)
Parameters
newWidth
intThe new width.
newHeight
intThe new height.
settings
ImageResizeSettingsThe resize settings.
Resize(int, int, ResizeType)
Resizes the image.
public override void Resize(int newWidth, int newHeight, ResizeType resizeType)
Parameters
newWidth
intThe new width.
newHeight
intThe new height.
resizeType
ResizeTypeThe resize type.
Rotate(float)
Rotate image around the center.
public virtual void Rotate(float angle)
Parameters
angle
floatThe rotate angle in degrees. Positive values will rotate clockwise.
Rotate(float, bool, Color)
Rotate image around the center.
public virtual void Rotate(float angle, bool resizeProportionally, Color backgroundColor)
Parameters
angle
floatThe rotate angle in degrees. Positive values will rotate clockwise.
resizeProportionally
boolif set to
true
you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.backgroundColor
ColorColor of the background.
Exceptions
- NotImplementedException
Not implemented exception
Save(Stream, ImageOptionsBase, Rectangle)
Saves the image's data to the specified stream in the specified file format according to save options.
public override void Save(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
Parameters
stream
StreamThe stream to save the image's data to.
optionsBase
ImageOptionsBaseThe save options.
boundsRectangle
RectangleThe destination image bounds rectangle. Set the empty rectangle for use source bounds.
SaveArgb32Pixels(Rectangle, int[])
Saves the 32-bit ARGB pixels.
public void SaveArgb32Pixels(Rectangle rectangle, int[] pixels)
Parameters
SaveCmyk32Pixels(Rectangle, int[])
Saves the pixels.
public void SaveCmyk32Pixels(Rectangle rectangle, int[] pixels)
Parameters
rectangle
RectangleThe rectangle to save pixels to.
pixels
int[]The CMYK pixels presented as the 32-bit integer values.
SaveCmykPixels(Rectangle, CmykColor[])
Saves the pixels. This method is deprecated. Please use more effective the SaveCmyk32Pixels(Rectangle, int[]) method.
[Obsolete("Method is obsolete")]
public void SaveCmykPixels(Rectangle rectangle, CmykColor[] pixels)
Parameters
SavePixels(Rectangle, Color[])
Saves the pixels.
public void SavePixels(Rectangle rectangle, Color[] pixels)
Parameters
SaveRawData(byte[], int, Rectangle, RawDataSettings)
Saves the raw data.
public void SaveRawData(byte[] data, int dataOffset, Rectangle rectangle, RawDataSettings rawDataSettings)
Parameters
data
byte[]The raw data.
dataOffset
intThe starting raw data offset.
rectangle
RectangleThe raw data rectangle.
rawDataSettings
RawDataSettingsThe raw data settings the data is in.
SetArgb32Pixel(int, int, int)
Sets an image 32-bit ARGB pixel for the specified position.
public void SetArgb32Pixel(int x, int y, int argb32Color)
Parameters
x
intThe pixel x location.
y
intThe pixel y location.
argb32Color
intThe 32-bit ARGB pixel for the specified position.
SetPalette(IColorPalette, bool)
Sets the image palette.
public override void SetPalette(IColorPalette palette, bool updateColors)
Parameters
palette
IColorPaletteThe palette to set.
updateColors
boolif set to
true
colors will be updated according to the new palette; otherwise color indexes remain unchanged. Note that unchanged indexes may crash the image on loading if some indexes have no corresponding palette entries.
SetPixel(int, int, Color)
Sets an image pixel for the specified position.
public void SetPixel(int x, int y, Color color)
Parameters
x
intThe pixel x location.
y
intThe pixel y location.
color
ColorThe pixel color for the specified position.
SetResolution(double, double)
Sets the resolution for this RasterImage.
public virtual void SetResolution(double dpiX, double dpiY)
Parameters
dpiX
doubleThe horizontal resolution, in dots per inch, of the RasterImage.
dpiY
doubleThe vertical resolution, in dots per inch, of the RasterImage.
ToBitmap()
Converts raster image to the bitmap. This method is not supported in versions from .Net7.0 and higher
public virtual Bitmap ToBitmap()
Returns
- Bitmap
The bitmap
UpdateMetadata()
Updates the image metadata.
protected virtual void UpdateMetadata()
WriteArgb32ScanLine(int, int[])
Writes the whole scan line to the specified scan line index.
public void WriteArgb32ScanLine(int scanLineIndex, int[] argb32Pixels)
Parameters
scanLineIndex
intZero based index of the scan line.
argb32Pixels
int[]The 32-bit ARGB colors array to write.
WriteScanLine(int, Color[])
Writes the whole scan line to the specified scan line index.
public void WriteScanLine(int scanLineIndex, Color[] pixels)