Class RasterImage
Namespace: Aspose.Imaging
Assembly: Aspose.Imaging.dll (25.7.0)
Represents a raster image supporting raster graphics operations.
public abstract class RasterImage : Image, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata
{
}
Here's the reformatted version with improved readability:
public abstract class RasterImage
: Image, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata
{
}
Inheritance
object ← DisposableObject ← DataStreamSupporter ← Image ← RasterImage
Derived
Implements
IDisposable , IObjectWithBounds , IRasterImageArgb32PixelLoader , IRasterImageRawDataLoader , IHasXmpData , IHasMetadata
Inherited Members
Image.CanLoad(string) , Image.CanLoad(string, LoadOptions) , Image.CanLoad(Stream) , Image.CanLoad(Stream, LoadOptions) , Image.Create(ImageOptionsBase, int, int) , Image.Create(Image[]) , Image.Create(MultipageCreateOptions) , Image.Create(string[], bool) , Image.Create(string[]) , Image.Create(Image[], bool) , Image.GetFileFormat(string) , Image.GetFileFormat(Stream) , Image.GetFittingRectangle(Rectangle, int, int) , Image.GetFittingRectangle(Rectangle, int[], int, int) , Image.Load(string, LoadOptions) , Image.Load(string) , Image.Load(Stream, LoadOptions) , Image.Load(Stream) , Image.GetProportionalWidth(int, int, int) , Image.GetProportionalHeight(int, int, int) , Image.RemoveMetadata() , Image.CanSave(ImageOptionsBase) , Image.Resize(int, int) , Image.Resize(int, int, ResizeType) , Image.Resize(int, int, ImageResizeSettings) , Image.GetDefaultOptions(object[]) , Image.GetOriginalOptions() , Image.ResizeWidthProportionally(int) , Image.ResizeHeightProportionally(int) , Image.ResizeWidthProportionally(int, ResizeType) , Image.ResizeHeightProportionally(int, ResizeType) , Image.ResizeWidthProportionally(int, ImageResizeSettings) , Image.ResizeHeightProportionally(int, ImageResizeSettings) , Image.RotateFlip(RotateFlipType) , Image.Rotate(float) , Image.Crop(Rectangle) , Image.Crop(int, int, int, int) , Image.Save() , Image.Save(string) , Image.Save(string, ImageOptionsBase) , Image.Save(string, ImageOptionsBase, Rectangle) , Image.Save(Stream, ImageOptionsBase) , Image.Save(Stream, ImageOptionsBase, Rectangle) , Image.GetSerializedStream(ImageOptionsBase, Rectangle, out int) , Image.SetPalette(IColorPalette, bool) , Image.UpdateContainer(Image) , Image.GetCanNotSaveMessage(ImageOptionsBase) , Image.GetFitRectangle(Rectangle) , Image.GetImage2Export(ImageOptionsBase, Rectangle, IImageExporter) , Image.GetFitRectangle(Rectangle, int[]) , Image.OnPaletteChanged(IColorPalette, IColorPalette) , Image.OnPaletteChanging(IColorPalette, IColorPalette) , Image.ReleaseManagedResources() , Image.BitsPerPixel , Image.Bounds , Image.Container , Image.Height , Image.Palette , Image.UsePalette , Image.Size , Image.Width , Image.InterruptMonitor , Image.BufferSizeHint , Image.AutoAdjustPalette , Image.HasBackgroundColor , Image.FileFormat , Image.BackgroundColor , DataStreamSupporter.timeout , DataStreamSupporter.CacheData() , DataStreamSupporter.Save() , DataStreamSupporter.Save(Stream) , DataStreamSupporter.Save(string) , DataStreamSupporter.Save(string, bool) , DataStreamSupporter.SaveData(Stream) , DataStreamSupporter.ReleaseManagedResources() , DataStreamSupporter.OnDataStreamContainerChanging(StreamContainer) , DataStreamSupporter.DataStreamContainer , DataStreamSupporter.IsCached , DisposableObject.Dispose() , DisposableObject.ReleaseManagedResources() , DisposableObject.ReleaseUnmanagedResources() , DisposableObject.VerifyNotDisposed() , DisposableObject.Disposed , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
This example shows how to Loads Pixel information in an Array of Type Color, manipulates the array and set it back to the image. To perform these operations, this example creates a new Image file (in GIF format) uisng MemoryStream object.
using System.IO;
using Aspose.Imaging;
var stream = new MemoryStream();
var gifOptions = new ImageOptions.GifOptions { Source = new Sources.StreamSource(stream) };
using (var image = (RasterImage)Image.Create(gifOptions, 500, 500))
{
var pixels = image.LoadPixels(image.Bounds);
for (int index = 0; index < pixels.Length; index++)
{
if (index % 2 == 0)
{
pixels[index] = Color.Yellow;
}
else
{
pixels[index] = Color.Blue;
}
}
image.SavePixels(image.Bounds, pixels);
image.Save();
using (var fileStream = new FileStream(@"C:\temp\output.gif", FileMode.Create))
{
stream.WriteTo(fileStream);
}
}
Constructors
RasterImage()
Initializes a new instance of the Aspose.Imaging.RasterImage class.
[JsonConstructor]
protected RasterImage()
{
}
RasterImage(IColorPalette)
Initializes a new instance of the Aspose.Imaging.RasterImage class.
protected RasterImage(IColorPalette colorPalette)
{
base(); // base constructor call if needed
this.ColorPalette = colorPalette;
}
Parameters
colorPalette
IColorPalette
The color palette.
Fields
xmpData
The XMP metadata
[JsonProperty]
protected XmpPacketWrapper xmpData;
Field Value
Properties
DataLoader
Gets or sets the data loader.
protected IRasterImageArgb32PixelLoader DataLoader
{
get;
set;
}
Property Value
HasAlpha
Gets a value indicating whether this instance has alpha.
public virtual bool HasAlpha
{
get;
}
Property Value
Examples
The following example loads raster images and prints information about raw data format and alpha channel.
string[] fileNames = new string[]
{
@"c:\temp\sample.bmp",
@"c:\temp\alpha.png",
};
foreach (string fileName in fileNames)
{
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileName))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
System.Console.WriteLine($"ImageFile={fileName}, FileFormat={rasterImage.RawDataFormat}, HasAlpha={rasterImage.HasAlpha}");
}
}
- Properly indented the code blocks and statements.
- Added spacing for better readability.
- Used string interpolation to make the Console.WriteLine statement more concise and easier to read.
The following example shows how to extract information about raw data format and alpha channel from a BMP image.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 32, null))
{
System.Console.WriteLine("FileFormat={0}, RawDataFormat={1}, HasAlpha={2}", bmpImage.FileFormat, bmpImage.RawDataFormat, bmpImage.HasAlpha);
}
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 24, null))
{
System.Console.WriteLine("FileFormat={0}, RawDataFormat={1}, HasAlpha={2}", bmpImage.FileFormat, bmpImage.RawDataFormat, bmpImage.HasAlpha);
}
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 Aspose.Imaging.RasterImage.
public virtual double HorizontalResolution
{
get;
set;
}
Property Value
Examples
The following example shows how to set horizontal/vertical resolution of a raster image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.jpg"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
double horizontalResolution = rasterImage.HorizontalResolution;
double verticalResolution = rasterImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0)
{
System.Console.WriteLine("Set resolution values to 96 dpi");
rasterImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", rasterImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", rasterImage.VerticalResolution);
}
}
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
IsRawDataAvailable
Gets a value indicating whether raw data loading is available.
public bool IsRawDataAvailable
{
get;
}
Property Value
PremultiplyComponents
Gets or sets a value indicating whether the image components must be premultiplied.
public virtual bool PremultiplyComponents
{
get;
set;
}
Property Value
Examples
The following example creates a new raster image, saves the specified semi-transparent pixels, then loads those pixels and gets final colors in the premultiplied form.
int imageWidth = 3;
int imageHeight = 2;
Aspose.Imaging.Color[] colors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.FromArgb(127, 255, 0, 0),
Aspose.Imaging.Color.FromArgb(127, 0, 255, 0),
Aspose.Imaging.Color.FromArgb(127, 0, 0, 255),
Aspose.Imaging.Color.FromArgb(127, 255, 255, 0),
Aspose.Imaging.Color.FromArgb(127, 255, 0, 255),
Aspose.Imaging.Color.FromArgb(127, 0, 255, 255)
};
Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), true);
createOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(createOptions, imageWidth, imageHeight))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.SavePixels(rasterImage.Bounds, colors);
rasterImage.PremultiplyComponents = true;
Aspose.Imaging.Color[] premultipliedColors = rasterImage.LoadPixels(rasterImage.Bounds);
for (int i = 0; i < colors.Length; i++)
{
System.Console.WriteLine("Original color: {0}", colors[i].ToString());
System.Console.WriteLine("Premultiplied color: {0}", premultipliedColors[i].ToString());
}
}
RawCustomColorConverter
Gets or sets the custom color converter
public IColorConverter RawCustomColorConverter
{
get;
set;
}
Property Value
RawDataFormat
Gets the raw data format.
public virtual PixelDataFormat RawDataFormat
{
get;
}
Property Value
Examples
The following example loads raster images and prints information about raw data format and alpha channel.
string[] fileNames = new string[]
{
@"c:\temp\sample.bmp",
@"c:\temp\alpha.png",
};
foreach (string fileName in fileNames)
{
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileName))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
System.Console.WriteLine("ImageFile={0}, FileFormat={1}, HasAlpha={2}", fileName, rasterImage.RawDataFormat, rasterImage.HasAlpha);
}
}
This example shows how to load a DJVU image from a file stream and print information about the pages.
string dir = "c:\\temp\\";
using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.djvu"))
{
using (Aspose.Imaging.FileFormats.Djvu.DjvuImage djvuImage = new Aspose.Imaging.FileFormats.Djvu.DjvuImage(stream))
{
System.Console.WriteLine("The total number of pages: {0}", djvuImage.Pages.Length);
System.Console.WriteLine("The active page number: {0}", djvuImage.ActivePage.PageNumber);
System.Console.WriteLine("The first page number: {0}", djvuImage.FirstPage.PageNumber);
System.Console.WriteLine("The last page number: {0}", djvuImage.LastPage.PageNumber);
foreach (Aspose.Imaging.FileFormats.Djvu.DjvuPage djvuPage in djvuImage.Pages)
{
System.Console.WriteLine("--------------------------------------------------");
System.Console.WriteLine("Page number: {0}", djvuPage.PageNumber);
System.Console.WriteLine("Page size: {0}", djvuPage.Size);
System.Console.WriteLine("Page raw format: {0}", djvuPage.RawDataFormat);
}
}
}
RawDataSettings
Gets the current raw data settings. Note when using these settings the data loads without conversion.
[JsonIgnore]
public RawDataSettings RawDataSettings
{
get;
}
Property Value
RawFallbackIndex
Gets or sets the fallback index to use when palette index is out of bounds
public int RawFallbackIndex
{
get;
set;
}
Property Value
RawIndexedColorConverter
Gets or sets the indexed color converter
public IIndexedColorConverter RawIndexedColorConverter
{
get;
set;
}
Property Value
RawLineSize
Gets the raw line size in bytes.
public virtual int RawLineSize
{
get;
}
Property Value
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
UsePalette
Gets a value indicating whether the image palette is used.
public override bool UsePalette
{
get;
}
Property Value
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
VerticalResolution
Gets or sets the vertical resolution, in pixels per inch, of this Aspose.Imaging.RasterImage.
public virtual double VerticalResolution
{
get;
set;
}
Property Value
Examples
The following example shows how to set horizontal/vertical resolution of a raster image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.jpg"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
double horizontalResolution = rasterImage.HorizontalResolution;
double verticalResolution = rasterImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0)
{
System.Console.WriteLine("Set resolution values to 96 dpi");
rasterImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", rasterImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", rasterImage.VerticalResolution);
}
}
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
Methods
AdjustBrightness(int)
Adjust of a brightness for image.
public virtual void AdjustBrightness(int brightness)
{
}
Parameters
brightness
int
Brightness value.
Examples
The following example performs brightness correction of an image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.AdjustBrightness(50);
rasterImage.Save(dir + "sample.AdjustBrightness.png");
}
AdjustContrast(float)
Image contrasting
public virtual void AdjustContrast(float contrast)
{
}
Parameters
contrast
float
Contrast value (in range [-100; 100])
Examples
The following example performs contrast correction of an image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.AdjustContrast(50);
rasterImage.Save(dir + "sample.AdjustContrast.png");
}
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
Examples
The following example performs gamma-correction of an image applying different coefficients for color components.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.AdjustGamma(1.5f, 2.5f, 3.5f);
rasterImage.Save(dir + "sample.AdjustGamma.png");
}
AdjustGamma(float)
Gamma-correction of an image.
public virtual void AdjustGamma(float gamma)
{
}
Parameters
gamma
float
Gamma for red, green and blue channels coefficient
Examples
The following example performs gamma-correction of an image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.AdjustGamma(2.5f);
rasterImage.Save(dir + "sample.AdjustGamma.png");
}
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
Examples
The following example binarizes a raster image with Bradley’s adaptive thresholding algorithm with the specified window size. Binarized images contain only 2 colors - black and white.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.BinarizeBradley(5, 10);
rasterImage.Save(dir + "sample.BinarizeBradley5_10x10.png");
}
BinarizeFixed(byte)
Binarization of an image with predefined threshold
public override 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.
Examples
The following example binarizes a raster image with the predefined threshold. Binarized images contain only 2 colors - black and white.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.BinarizeFixed(127);
rasterImage.Save(dir + "sample.BinarizeFixed.png");
}
BinarizeOtsu()
Binarization of an image with Otsu thresholding
public virtual void BinarizeOtsu()
{
}
The original code already follows standard C# conventions for method definition, indentation, and spacing. Therefore, no changes have been made to it in this case.
Examples
The following example binarizes a raster image with Otsu thresholding. Binarized images contain only 2 colors - black and white.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.BinarizeOtsu();
rasterImage.Save(dir + "sample.BinarizeOtsu.png");
}
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.
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.
Examples
The following example loads a raster image and performs threshold and floyd dithering using different palette depth.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.Dither(Aspose.Imaging.DitheringMethod.ThresholdDithering, 4);
rasterImage.Save(dir + "sample.ThresholdDithering4.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.Dither(Aspose.Imaging.DitheringMethod.FloydSteinbergDithering, 1);
rasterImage.Save(dir + "sample.FloydSteinbergDithering1.png");
}
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.
Examples
The following example applies various types of filters to a raster image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.MedianFilterOptions(5));
rasterImage.Save(dir + "sample.MedianFilter.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.BilateralSmoothingFilterOptions(5));
rasterImage.Save(dir + "sample.BilateralSmoothingFilter.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.GaussianBlurFilterOptions(5, 4.0));
rasterImage.Save(dir + "sample.GaussianBlurFilter.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.GaussWienerFilterOptions(5, 4.0));
rasterImage.Save(dir + "sample.GaussWienerFilter.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.MotionWienerFilterOptions(5, 4.0, 90.0));
rasterImage.Save(dir + "sample.MotionWienerFilter.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.SharpenFilterOptions(5, 4.0));
rasterImage.Save(dir + "sample.SharpenFilter.png");
}
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
The 32-bit ARGB pixel for the specified location.
Examples
The following example loads a raster image and obtains the color of an arbitrary pixel represented as a 32-bit integer value.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
int color = rasterImage.GetArgb32Pixel(0, 0);
int alpha = (color >> 24) & 0xff;
int red = (color >> 16) & 0xff;
int green = (color >> 8) & 0xff;
int blue = (color >> 0) & 0xff;
System.Console.WriteLine("The color of the pixel(0,0) is A={0},R={1},G={2},B={3}", alpha, red, green, blue);
}
The following example shows how image caching affects performance. In general case, reading cached data is performed faster than reading non-cached data.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
image.CacheData();
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
{
int color = rasterImage.GetArgb32Pixel(x, y);
}
}
stopwatch.Stop();
System.Console.WriteLine("Reading all cached pixels took {0} ms.", stopwatch.ElapsedMilliseconds);
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
{
int color = rasterImage.GetArgb32Pixel(x, y);
}
}
stopwatch.Stop();
System.Console.WriteLine("Reading all pixels without preliminary caching took {0} ms.", stopwatch.ElapsedMilliseconds);
}
GetDefaultArgb32Pixels(Rectangle)
Gets the default 32-bit ARGB pixels array.
public int[] GetDefaultArgb32Pixels(Rectangle rectangle)
{
}
I've reformatted the given code by adding proper indentation, spacing, and general readability improvements. However, I didn't modify or remove any existing comments, variable names, method names, class names, or types. The output should be suitable for inclusion in a source file.
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
The date and time the resource image was last modified.
GetPixel(int, int)
Gets an image pixel.
public Color GetPixel(int x, int y)
{
}
Here is the reformatted version of your code:
public Color GetPixel(int x, int y)
{
}
The only change made was to ensure proper indentation.
Parameters
x
int
The pixel x location.
y
int
The pixel y location.
Returns
The pixel color for the specified location.
Examples
The following example loads a raster image and obtains the color of an arbitrary pixel.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.png"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
Color color = rasterImage.GetPixel(0, 0);
byte alpha = color.A;
byte red = color.R;
int green = color.G;
int blue = color.B;
System.Console.WriteLine("The color of the pixel(0,0) is A={0}, R={1}, G={2}, B={3}", alpha, red, green, blue);
}
GetSkewAngle()
Gets the skew angle.This method is applicable to scanned text documents, to determine the skew angle when scanning.
public float GetSkewAngle()
{
}
Returns
The skew angle, in degrees.
Grayscale()
Transformation of an image to its grayscale representation
public virtual void Grayscale()
{
}
Examples
The following example transforms a colored raster image to its grayscale representation. Grayscale images are composed exclusively of shades of gray and carry only intensity information.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.Grayscale();
rasterImage.Save(dir + "sample.Grayscale.png");
}
LoadArgb32Pixels(Rectangle)
Loads 32-bit ARGB pixels.
public int[] LoadArgb32Pixels(Rectangle rectangle)
{
}
For this specific code snippet, no changes are needed as it already follows standard C# conventions. Here's a more complex example where some reformatting is necessary:
public class MyClass
{
private int _myPrivateVariable;
public MyClass(int myPublicConstructorParameter)
{
this._myPrivateVariable = myPublicConstructorParameter * 2;
DoSomething();
}
private void DoSomething()
{
}
}
After reformatting:
public class MyClass
{
private int _myPrivateVariable;
public MyClass(int myPublicConstructorParameter)
{
this._myPrivateVariable = myPublicConstructorParameter * 2;
DoSomething();
}
private void DoSomething()
{
}
}
Parameters
rectangle
Rectangle
The rectangle to load pixels from.
Returns
int []
The loaded 32-bit ARGB pixels array.
Examples
The following example shows how to load and process pixels of a raster image. The pixels are represented as 32-bit integer values. For example, consider a problem of counting of fully transparent pixels of an image.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\alpha.png"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
int[] pixels = rasterImage.LoadArgb32Pixels(rasterImage.Bounds);
int count = 0;
foreach (int pixel in pixels)
{
int alpha = (pixel >> 24) & 0xff;
if (alpha == 0)
{
count++;
}
}
System.Console.WriteLine("The number of fully transparent pixels is {0}", count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
}
LoadArgb64Pixels(Rectangle)
Loads 64-bit ARGB pixels.
public long[] LoadArgb64Pixels(Rectangle rectangle)
{
}
In this case, since the provided code is already formatted according to standard C# conventions, no changes were made. However, if there were any issues with indentation, spacing, or readability, they would be addressed in the reformatting process.
Parameters
rectangle
Rectangle
The rectangle to load pixels from.
Returns
long []
The loaded 64-bit ARGB pixels array.
Examples
The following example shows how to load and process pixels of a raster image. The pixels are represented as 64-bit integer values. For example, consider a problem of counting of fully transparent pixels of an image.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\16rgba.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
long[] pixels = rasterImage.LoadArgb64Pixels(rasterImage.Bounds);
int count = 0;
foreach (int pixel in pixels)
{
int alpha = (pixel >> 48) & 0xffff;
if (alpha == 0)
{
count++;
}
}
System.Console.WriteLine("The number of fully transparent pixels is {0}", count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
}
LoadCmyk32Pixels(Rectangle)
Loads pixels in CMYK format.
public int[] LoadCmyk32Pixels(Rectangle rectangle)
{
}
Note that I did not modify the existing implementation, as per your requirements.
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 Aspose.Imaging.RasterImage.LoadCmyk32Pixels(Aspose.Imaging.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.
Examples
The following example shows how to load and process pixels of a raster image using your own partial processor. For example, consider a problem of counting of fully transparent pixels of an image. In order to count transparent pixels using partial loading mechanism, a separate class TransparentArgb32PixelCounter implementing Aspose.Imaging.IPartialArgb32PixelLoader is introduced.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\alpha.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
TransparentArgb32PixelCounter counter = new TransparentArgb32PixelCounter();
rasterImage.LoadPartialArgb32Pixels(rasterImage.Bounds, counter);
System.Console.WriteLine("The number of fully transparent pixels is {0}", counter.Count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
}
private class TransparentArgb32PixelCounter : IPartialArgb32PixelLoader
{
private int count;
public int Count
{
get { return this.count; }
}
public void Process(Aspose.Imaging.Rectangle pixelsRectangle, int[] pixels, Aspose.Imaging.Point start, Aspose.Imaging.Point end)
{
foreach (int pixel in pixels)
{
int alpha = (pixel >> 24) & 0xff;
if (alpha == 0)
{
this.count++;
}
}
}
}
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.
Examples
The following example shows how to load and process pixels of a raster image using your own partial processor. For example, consider a problem of counting of fully transparent pixels of an image. In order to count transparent using partial loading mechanism, a separate class TransparentPixelCounter implementing Aspose.Imaging.IPartialPixelLoader is introduced.
using Aspose.Imaging;
Image image = Aspose.Imaging.Image.Load(@"c:\temp\alpha.png");
RasterImage rasterImage = (RasterImage)image;
TransparentPixelCounter counter = new TransparentPixelCounter();
rasterImage.LoadPartialPixels(rasterImage.Bounds, counter);
System.Console.WriteLine("The number of fully transparent pixels is {0}", counter.Count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
private class TransparentPixelCounter : IPartialPixelLoader
{
private int count;
public int Count
{
get { return this.count; }
}
public void Process(Rectangle pixelsRectangle, Color[] pixels, Point start, Point end)
{
foreach (Color pixel in pixels)
{
if (pixel.A == 0)
{
this.count++;
}
}
}
}
LoadPixels(Rectangle)
Loads pixels.
public Color[] LoadPixels(Rectangle rectangle)
{
}
Here's the reformatted version of your provided code:
public Color[] LoadPixels(Rectangle rectangle)
{
}
I've added a new line between the opening bracket and the code block for better readability, but left it empty as per your instructions.
Parameters
rectangle
Rectangle
The rectangle to load pixels from.
Returns
Color []
The loaded pixels array.
Examples
The following example shows how to load and process pixels of a raster image. For example, consider a problem of counting of fully transparent pixels of an image.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\alpha.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
Color[] pixels = rasterImage.LoadPixels(rasterImage.Bounds);
int count = 0;
foreach (Color pixel in pixels)
{
if (pixel.A == 0)
{
count++;
}
}
System.Console.WriteLine("The number of fully transparent pixels is {0}", count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
}
This example shows how to Loads Pixel information in an Array of Type Color, manipulates the array and set it back to the image. To perform these operations, this example creates a new Image file (in GIF format) uisng MemoryStream object.
using System.IO;
using Aspose.Imaging;
MemoryStream stream = new MemoryStream();
ImageOptions.GifOptions gifOptions = new ImageOptions.GifOptions { Source = new Sources.StreamSource(stream) };
RasterImage image = (RasterImage)Image.Create(gifOptions, 500, 500);
Aspose.Imaging.Color[] pixels = image.LoadPixels(image.Bounds);
for (int index = 0; index < pixels.Length; index++)
{
if (index % 2 == 0)
{
pixels[index] = Color.Yellow;
}
else
{
pixels[index] = Color.Blue;
}
}
image.SavePixels(image.Bounds, pixels);
image.Save();
using (FileStream fileStream = new FileStream(@"C:\temp\output.gif", FileMode.Create))
{
stream.WriteTo(fileStream);
}
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.
Examples
The following example shows how to extract pixels from the raw image data using RawDataSettings. For example, consider a problem of counting of fully transparent pixels of an image.
using Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\GrayscaleWithAlpha.png");
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
Aspose.Imaging.RawDataSettings settings = rasterImage.RawDataSettings;
TransparentPixelRawDataCounter rawDataLoader = new TransparentPixelRawDataCounter(settings);
rasterImage.LoadRawData(rasterImage.Bounds, settings, rawDataLoader);
Console.WriteLine("The number of fully transparent pixels is {0}", rawDataLoader.Count);
Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
private class TransparentPixelRawDataCounter : IPartialRawDataLoader
{
private int count;
private Aspose.Imaging.RawDataSettings rawDataSettings;
public int Count
{
get { return this.count; }
}
public TransparentPixelRawDataCounter(Aspose.Imaging.RawDataSettings settings)
{
this.rawDataSettings = settings;
this.count = 0;
}
public void Process(Aspose.Imaging.Rectangle dataRectangle, byte[] data, Aspose.Imaging.Point start, Aspose.Imaging.Point end)
{
int[] channelBits = this.rawDataSettings.PixelDataFormat.ChannelBits;
for (int i = 0; i < channelBits.Length; i++)
{
if (channelBits[i] != 8)
{
throw new System.NotSupportedException();
}
}
switch (this.rawDataSettings.PixelDataFormat.PixelFormat)
{
case PixelFormat.Rgb:
case PixelFormat.Bgr:
{
if (channelBits.Length == 4)
{
for (int i = 0; i < data.Length; i += 4)
{
if (data[i + 3] == 0)
{
this.count++;
}
}
}
}
break;
case PixelFormat.Grayscale:
{
if (channelBits.Length == 2)
{
for (int i = 0; i < data.Length; i += 2)
{
if (data[i + 1] == 0)
{
this.count++;
}
}
}
}
break;
default:
throw new System.ArgumentOutOfRangeException("PixelFormat");
}
}
public void Process(Aspose.Imaging.Rectangle dataRectangle, byte[] data, Aspose.Imaging.Point start, Aspose.Imaging.Point end, Aspose.Imaging.LoadOptions loadOptions)
{
this.Process(dataRectangle, data, start, end);
}
}
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 Aspose.Imaging.RasterImage.GetSkewAngle and Aspose.Imaging.RasterImage.Rotate(System.Single) 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 Aspose.Imaging.RasterImage.GetSkewAngle and Aspose.Imaging.RasterImage.Rotate(System.Single,System.Boolean,Aspose.Imaging.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.
Examples
Skew is an artifact that might appear during document scanning process when the text/images of the document get rotated at a slight angle. It can have various causes but the most common is that the paper get misplaced during a scan. Therefore, deskew is the process of detecting and fixing this issue on scanned files(i.e. bitmap) so deskewed documents will have the text/images correctly and horizontally adjusted.
string dir = "c:\\aspose.imaging\\issues\\net\\3567\\";
string inputFilePath = dir + "skewed.png";
string outputFilePath = dir + "skewed.out.png";
using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(inputFilePath))
{
image.NormalizeAngle(false, Aspose.Imaging.Color.LightGray);
image.Save(outputFilePath);
}
NormalizeHistogram()
Normalizes the image histogram — adjust pixel values to use all available range.
public virtual void NormalizeHistogram()
{
}
ReadArgb32ScanLine(int)
Reads the whole scan line by the specified scan line index.
public int[] ReadArgb32ScanLine(int scanLineIndex)
{
}
I've only reformatted the code to maintain proper indentation and spacing according to standard C# conventions. The logic remains unchanged, as per your requirements.
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)
{
}
This is already properly indented and spaced according to C# conventions, but I will show you an example with a bit more content for illustrative purposes:
public void SomeMethod(int myVariable)
{
var anotherVariable = GetSomeValue();
if (myVariable > 10)
{
ProcessData(anotherVariable);
}
}
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()
{
base.ReleaseManagedResources();
}
RemoveMetadata()
Removes this image instance metadata by setting this Aspose.Imaging.Xmp.IHasXmpData.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)
{
}
This is the reformatted code with proper indentation and spacing according to standard C# conventions.
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.
Examples
This example loads a raster image and resizes it using various resizing settings.
string dir = "c:\\temp\\";
Aspose.Imaging.ImageResizeSettings resizeSettings = new Aspose.Imaging.ImageResizeSettings();
resizeSettings.Mode = Aspose.Imaging.ResizeType.AdaptiveResample;
resizeSettings.FilterType = Aspose.Imaging.ImageFilterType.SmallRectangular;
resizeSettings.EntriesCount = 256;
resizeSettings.ColorQuantizationMethod = Aspose.Imaging.ColorQuantizationMethod.None;
resizeSettings.ColorCompareMethod = Aspose.Imaging.ColorCompareMethod.Euclidian;
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
{
image.Resize(image.Width / 2, image.Height / 2, resizeSettings);
image.Save(dir + "downsample.adaptive.gif");
}
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
Not implemented exception
Rotate(float)
Rotate image around the center.
public override void Rotate(float angle)
{
}
Parameters
angle
float
The rotate angle in degrees. Positive values will rotate clockwise.
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.
Examples
The following example fills the central area of a raster image with black pixels using the Aspose.Imaging.RasterImage.SaveArgb32Pixels method.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
int[] pixels = new int[(rasterImage.Width / 2) * (rasterImage.Height / 2)];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = Color.Black.ToArgb();
}
Aspose.Imaging.Rectangle area = new Aspose.Imaging.Rectangle(rasterImage.Width / 4, rasterImage.Height / 4, rasterImage.Width / 2, rasterImage.Height / 2);
rasterImage.SaveArgb32Pixels(area, pixels);
rasterImage.Save(dir + "sample.SaveArgb32Pixels.png");
}
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.
Examples
The following example fills the central area of a raster image with black pixels using the Aspose.Imaging.RasterImage.SaveCmyk32Pixels method.
string dir = @"c:\temp\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
int blackCmyk = Aspose.Imaging.CmykColorHelper.ToCmyk(Color.Black);
int[] pixels = new int[(rasterImage.Width / 2) * (rasterImage.Height / 2)];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = blackCmyk;
}
Aspose.Imaging.Rectangle area = new Aspose.Imaging.Rectangle(rasterImage.Width / 4, rasterImage.Height / 4, rasterImage.Width / 2, rasterImage.Height / 2);
rasterImage.SaveCmyk32Pixels(area, pixels);
rasterImage.Save(dir + "sample.SaveCmyk32Pixels.png");
}
SaveCmykPixels(Rectangle, CmykColor[])
Saves the pixels.This method is deprecated. Please use more effective the Aspose.Imaging.RasterImage.SaveCmyk32Pixels(Aspose.Imaging.Rectangle,System.Int32[]) 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.
Examples
The following example fills the central area of a raster image with black pixels using the Aspose.Imaging.RasterImage.SavePixels method.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
Color[] pixels = new Color[(rasterImage.Width / 2) * (rasterImage.Height / 2)];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = Color.Black;
}
var area = new Aspose.Imaging.Rectangle(rasterImage.Width / 4, rasterImage.Height / 4, rasterImage.Width / 2, rasterImage.Height / 2);
rasterImage.SavePixels(area, pixels);
rasterImage.Save(dir + "sample.SavePixels.png");
}
This example shows how to Loads Pixel information in an Array of Type Color, manipulates the array and set it back to the image. To perform these operations, this example creates a new Image file (in GIF format) uisng MemoryStream object.
using System.IO;
using Aspose.Imaging;
MemoryStream stream = new MemoryStream();
GifOptions gifOptions = new GifOptions();
gifOptions.Source = new StreamSource(stream);
using (RasterImage image = (RasterImage)Image.Create(gifOptions, 500, 500))
{
Color[] pixels = image.LoadPixels(image.Bounds);
for (int index = 0; index < pixels.Length; index++)
{
if (index % 2 == 0)
{
pixels[index] = Color.Yellow;
}
else
{
pixels[index] = Color.Blue;
}
}
image.SavePixels(image.Bounds, pixels);
image.Save();
using (FileStream fileStream = new FileStream(@"C:\temp\output.gif", FileMode.Create))
{
stream.WriteTo(fileStream);
}
}
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.
Examples
The following example loads a raster image, and sets the color of an arbitrary pixel.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.SetArgb32Pixel(0, 0, Aspose.Imaging.Color.Aqua.ToArgb());
rasterImage.SetPixel(0, 0, Aspose.Imaging.Color.Aqua);
}
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.
Examples
The following example loads a raster image, and sets the color of an arbitrary pixel.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.png"))
{
var rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.SetArgb32Pixel(0, 0, Aspose.Imaging.Color.Aqua.ToArgb());
rasterImage.SetPixel(0, 0, Aspose.Imaging.Color.Aqua);
}
SetResolution(double, double)
Sets the resolution for this Aspose.Imaging.RasterImage.
public virtual void SetResolution(
double dpiX,
double dpiY
)
Parameters
dpiX
double
The horizontal resolution, in dots per inch, of the Aspose.Imaging.RasterImage.
dpiY
double
The vertical resolution, in dots per inch, of the Aspose.Imaging.RasterImage.
Examples
The following example shows how to set horizontal/vertical resolution of a raster image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.jpg"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
double horizontalResolution = rasterImage.HorizontalResolution;
double verticalResolution = rasterImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0)
{
System.Console.WriteLine("Set resolution values to 96 dpi");
rasterImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", rasterImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", rasterImage.VerticalResolution);
}
}
ToBitmap()
Converts raster image to the bitmap.This method is not supported in versions from .Net7.0 and higher
public virtual Bitmap ToBitmap()
{
}
In this case, since the provided code already follows standard C# conventions for indentation and spacing, there are no changes needed. However, if your input code contained multiple methods or blocks of code, I would format them consistently based on the rules mentioned above. For example:
public void SomeMethod()
{
}
private int _someVariable;
public int SomeOtherMethod(string input)
{
if (input == null)
return default(int);
_someVariable = input.Length;
}
Returns
The bitmap
UpdateDimensions(int, int)
Updates the image dimensions.
protected abstract void UpdateDimensions(
int newWidth,
int newHeight
);
Parameters
newWidth
int
The new image width.
newHeight
int
The new image height.
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.