Table of Contents

Class RasterImage

Namespace
Aspose.Imaging
Assembly
Aspose.Imaging.dll

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 IColorPalette

The color palette.

Fields

xmpData

The XMP metadata

protected XmpPacketWrapper xmpData

Field Value

XmpPacketWrapper

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

bool

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

Color

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 int

Brightness value.

AdjustContrast(float)

Image contrasting

public virtual void AdjustContrast(float contrast)

Parameters

contrast float

Contrast value (in range [-100; 100])

AdjustGamma(float)

Gamma-correction of an image.

public virtual void AdjustGamma(float gamma)

Parameters

gamma float

Gamma 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 float

Gamma for red channel coefficient

gammaGreen float

Gamma for green channel coefficient

gammaBlue float

Gamma 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 double

The 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 double

The brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.

windowSize int

The 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 byte

Threshold 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 Point

The background image blending origin.

overlay RasterImage

The overlay image.

overlayArea Rectangle

The overlay area.

overlayAlpha byte

The 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 Point

The background image blending origin.

overlay RasterImage

The overlay image.

overlayAlpha byte

The overlay alpha.

Crop(Rectangle)

Crops the specified rectangle.

public virtual void Crop(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle.

Crop(int, int, int, int)

Crop image with shifts.

public virtual void Crop(int leftShift, int rightShift, int topShift, int bottomShift)

Parameters

leftShift int

The left shift.

rightShift int

The right shift.

topShift int

The top shift.

bottomShift int

The bottom shift.

Dither(DitheringMethod, int)

Performs dithering on the current image.

public void Dither(DitheringMethod ditheringMethod, int bitsCount)

Parameters

ditheringMethod DitheringMethod

The dithering method.

bitsCount int

The 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 DitheringMethod

The dithering method.

bitsCount int

The final bits count for dithering.

customPalette IColorPalette

The custom palette for dithering.

Filter(Rectangle, FilterOptionsBase)

Filters the specified rectangle.

public virtual void Filter(Rectangle rectangle, FilterOptionsBase options)

Parameters

rectangle Rectangle

The rectangle.

options FilterOptionsBase

The options.

GetArgb32Pixel(int, int)

Gets an image 32-bit ARGB pixel.

public int GetArgb32Pixel(int x, int y)

Parameters

x int

The pixel x location.

y int

The pixel y location.

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 Rectangle

The 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 Rectangle

The rectangle to get pixels for.

partialPixelLoader IPartialArgb32PixelLoader

The 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 Rectangle

The rectangle to get pixels for.

partialRawDataLoader IPartialRawDataLoader

The partial raw data loader.

rawDataSettings RawDataSettings

The raw data settings.

GetDefaultRawData(Rectangle, RawDataSettings)

Gets the default raw data array.

public byte[] GetDefaultRawData(Rectangle rectangle, RawDataSettings rawDataSettings)

Parameters

rectangle Rectangle

The rectangle to get raw data for.

rawDataSettings RawDataSettings

The 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 bool

if 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

x int

The pixel x location.

y int

The pixel y location.

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 Rectangle

The 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 Rectangle

The 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 Rectangle

The 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 Rectangle

The 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 Rectangle

The desired rectangle.

partialPixelLoader IPartialArgb32PixelLoader

The 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 Rectangle

The desired rectangle.

partialPixelLoader IPartialArgb64PixelLoader

The 64-bit ARGB pixel loader.

LoadPartialPixels(Rectangle, IPartialPixelLoader)

Loads pixels partially by packs.

public void LoadPartialPixels(Rectangle desiredRectangle, IPartialPixelLoader pixelLoader)

Parameters

desiredRectangle Rectangle

The desired rectangle.

pixelLoader IPartialPixelLoader

The pixel loader.

LoadPixels(Rectangle)

Loads pixels.

public Color[] LoadPixels(Rectangle rectangle)

Parameters

rectangle Rectangle

The 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 Rectangle

The rectangle to load raw data from.

rawDataSettings RawDataSettings

The raw data settings to use for loaded data. Note if data is not in the format specified then data conversion will be performed.

rawDataLoader IPartialRawDataLoader

The raw data loader.

LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader)

Loads raw data.

public void LoadRawData(Rectangle rectangle, Rectangle destImageBounds, RawDataSettings rawDataSettings, IPartialRawDataLoader rawDataLoader)

Parameters

rectangle Rectangle

The rectangle to load raw data from.

destImageBounds Rectangle

The dest image bounds.

rawDataSettings RawDataSettings

The raw data settings to use for loaded data. Note if data is not in the format specified then data conversion will be performed.

rawDataLoader IPartialRawDataLoader

The 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 bool

if 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 Color

Color of the background.

ReadArgb32ScanLine(int)

Reads the whole scan line by the specified scan line index.

public int[] ReadArgb32ScanLine(int scanLineIndex)

Parameters

scanLineIndex int

Zero 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 int

Zero 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()

Removes this image instance metadata by setting this XmpData value to null.

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 Color

Old color to be replaced.

oldColorDiff byte

Allowed difference in old color to be able to widen replaced color tone.

newColor Color

New 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 int

Old color ARGB value to be replaced.

oldColorDiff byte

Allowed difference in old color to be able to widen replaced color tone.

newColorArgb int

New 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 Color

New 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 int

New 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 int

The new width.

newHeight int

The new height.

settings ImageResizeSettings

The resize settings.

Resize(int, int, ResizeType)

Resizes the image.

public override void Resize(int newWidth, int newHeight, ResizeType resizeType)

Parameters

newWidth int

The new width.

newHeight int

The new height.

resizeType ResizeType

The resize type.

Rotate(float)

Rotate image around the center.

public virtual void Rotate(float angle)

Parameters

angle float

The 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 float

The rotate angle in degrees. Positive values will rotate clockwise.

resizeProportionally bool

if 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 Color

Color 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 Stream

The stream to save the image's data to.

optionsBase ImageOptionsBase

The save options.

boundsRectangle Rectangle

The 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

rectangle Rectangle

The rectangle to save pixels to.

pixels int[]

The 32-bit ARGB pixels array.

SaveCmyk32Pixels(Rectangle, int[])

Saves the pixels.

public void SaveCmyk32Pixels(Rectangle rectangle, int[] pixels)

Parameters

rectangle Rectangle

The 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

rectangle Rectangle

The rectangle to save pixels to.

pixels CmykColor

The CMYK pixels array.

SavePixels(Rectangle, Color[])

Saves the pixels.

public void SavePixels(Rectangle rectangle, Color[] pixels)

Parameters

rectangle Rectangle

The rectangle to save pixels to.

pixels Color[]

The pixels array.

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 int

The starting raw data offset.

rectangle Rectangle

The raw data rectangle.

rawDataSettings RawDataSettings

The 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 int

The pixel x location.

y int

The pixel y location.

argb32Color int

The 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 IColorPalette

The palette to set.

updateColors bool

if 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 int

The pixel x location.

y int

The pixel y location.

color Color

The 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 double

The horizontal resolution, in dots per inch, of the RasterImage.

dpiY double

The 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 int

Zero 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)

Parameters

scanLineIndex int

Zero based index of the scan line.

pixels Color[]

The pixel colors array to write.