Class BmpImage
Namespace: Aspose.Imaging.FileFormats.Bmp
Assembly: Aspose.Imaging.dll (25.2.0)
You can effortlessly handle Bitmap (BMP) and Device Independent Bitmap (DIB) files, facilitating efficient manipulation and processing of raster images. Performing various operations on images, this API streamlines the workflow, offering developers a reliable toolkit for working with BMP and DIB formats in their software applications.
[JsonObject(MemberSerialization.OptIn)]
public sealed class BmpImage : RasterCachedImage, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata
Inheritance
object ← DisposableObject ← DataStreamSupporter ← Image ← RasterImage ← RasterCachedImage ← BmpImage
Implements
IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata
Inherited Members
RasterCachedImage.CacheData(), RasterCachedImage.Blend(Point, RasterImage, Rectangle, byte), RasterCachedImage.Resize(int, int, ResizeType), RasterCachedImage.Resize(int, int, ImageResizeSettings), RasterCachedImage.RotateFlip(RotateFlipType), RasterCachedImage.Rotate(float, bool, Color), RasterCachedImage.Crop(Rectangle), RasterCachedImage.Dither(DitheringMethod, int, IColorPalette), RasterCachedImage.Grayscale(), RasterCachedImage.BinarizeFixed(byte), RasterCachedImage.BinarizeOtsu(), RasterCachedImage.BinarizeBradley(double, int), RasterCachedImage.BinarizeBradley(double), RasterCachedImage.AdjustBrightness(int), RasterCachedImage.AdjustContrast(float), RasterCachedImage.AdjustGamma(float, float, float), RasterCachedImage.AdjustGamma(float), RasterCachedImage.IsCached, RasterImage.RemoveMetadata(), RasterImage.Save(Stream, ImageOptionsBase, Rectangle), RasterImage.GetModifyDate(bool), RasterImage.Dither(DitheringMethod, int), RasterImage.Dither(DitheringMethod, int, IColorPalette), RasterImage.GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader), RasterImage.GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings), RasterImage.GetDefaultArgb32Pixels(Rectangle), RasterImage.GetDefaultRawData(Rectangle, RawDataSettings), RasterImage.GetArgb32Pixel(int, int), RasterImage.GetPixel(int, int), RasterImage.SetArgb32Pixel(int, int, int), RasterImage.SetPixel(int, int, Color), RasterImage.ReadScanLine(int), RasterImage.ReadArgb32ScanLine(int), RasterImage.WriteScanLine(int, Color[]), RasterImage.WriteArgb32ScanLine(int, int[]), RasterImage.LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader), RasterImage.LoadPartialPixels(Rectangle, IPartialPixelLoader), RasterImage.LoadArgb32Pixels(Rectangle), RasterImage.LoadArgb64Pixels(Rectangle), RasterImage.LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader), RasterImage.LoadPixels(Rectangle), RasterImage.LoadCmykPixels(Rectangle), RasterImage.LoadCmyk32Pixels(Rectangle), RasterImage.LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader), RasterImage.LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader), RasterImage.SaveRawData(byte[], int, Rectangle, RawDataSettings), RasterImage.SaveArgb32Pixels(Rectangle, int[]), RasterImage.SavePixels(Rectangle, Color[]), RasterImage.SaveCmykPixels(Rectangle, CmykColor[]), RasterImage.SaveCmyk32Pixels(Rectangle, int[]), RasterImage.SetResolution(double, double), RasterImage.SetPalette(IColorPalette, bool), RasterImage.Resize(int, int, ImageResizeSettings), RasterImage.Rotate(float, bool, Color), RasterImage.Rotate(float), RasterImage.BinarizeFixed(byte), RasterImage.BinarizeOtsu(), RasterImage.BinarizeBradley(double), RasterImage.BinarizeBradley(double, int), RasterImage.Blend(Point, RasterImage, Rectangle, byte), RasterImage.Blend(Point, RasterImage, byte), RasterImage.Grayscale(), RasterImage.AdjustBrightness(int), RasterImage.AdjustContrast(float), RasterImage.AdjustGamma(float, float, float), RasterImage.AdjustGamma(float), RasterImage.GetSkewAngle(), RasterImage.NormalizeAngle(), RasterImage.NormalizeAngle(bool, Color), RasterImage.Filter(Rectangle, FilterOptionsBase), RasterImage.ReplaceColor(Color, byte, Color), RasterImage.ReplaceColor(int, byte, int), RasterImage.ReplaceNonTransparentColors(Color), RasterImage.ReplaceNonTransparentColors(int), RasterImage.ToBitmap(), RasterImage.PremultiplyComponents, RasterImage.UseRawData, RasterImage.UpdateXmpData, RasterImage.XmpData, RasterImage.RawIndexedColorConverter, RasterImage.RawCustomColorConverter, RasterImage.RawFallbackIndex, RasterImage.RawDataSettings, RasterImage.UsePalette, RasterImage.RawDataFormat, RasterImage.RawLineSize, RasterImage.IsRawDataAvailable, RasterImage.HorizontalResolution, RasterImage.VerticalResolution, RasterImage.HasTransparentColor, RasterImage.HasAlpha, RasterImage.TransparentColor, RasterImage.ImageOpacity, 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.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.CacheData(), DataStreamSupporter.Save(), DataStreamSupporter.Save(Stream), DataStreamSupporter.Save(string), DataStreamSupporter.Save(string, bool), DataStreamSupporter.DataStreamContainer, DataStreamSupporter.IsCached, DisposableObject.Dispose(), DisposableObject.Disposed, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Examples
Decompress BMP image which was previously compressed using DXT1 compression algorithm.```csharp [C#]
using (var image = Image.Load("CompressedTiger.bmp"))
{
image.Save("DecompressedTiger.bmp", new BmpOptions());
}
Compress BMP image using DXT1 compression algorithm.```csharp
[C#]
using (var image = Image.Load("Tiger.bmp"))
{
image.Save("CompressedTiger.bmp", new BmpOptions { Compression = BitmapCompression.Dxt1 });
}
The example shows how to remove any object from the image using Graphics Path with Telea algorithm.```csharp [C#]
var imageFilePath = "ball.png";
using (var image = Image.Load(imageFilePath))
{
var pngImage = (PngImage)image;
var mask = new GraphicsPath();
var firstFigure = new Figure();
firstFigure.AddShape(new EllipseShape(new RectangleF(350, 170, 570 - 350, 400 - 170)));
mask.AddFigure(firstFigure);
var options = new TeleaWatermarkOptions(mask);
var result = WatermarkRemover.PaintOver(pngImage, options);
result.Save(outputPath);
}
The example shows how to export a BmpImage with the Rgb compression type.```csharp
[C#]
string sourcePath = "input.png";
// Load a PNG image from a file.
using (Image pngImage = Image.Load(sourcePath))
{
// BMP image is saved with transparency support by default, that is achieved by using the BitmapCompression.Bitfields compression method.
// To save a BMP image with the Rgb compression method, the BmpOptions with the Compression property set to BitmapCompression.Rgb should be specified.
pngImage.Save(outputPath, new BmpOptions() { Compression = BitmapCompression.Rgb });
}
The example shows how to remove any object from the image using Graphics Path with Content Aware fill algorithm.```csharp [C#]
var imageFilePath = "ball.png";
using (var image = Image.Load(imageFilePath))
{
var pngImage = (PngImage)image;
var mask = new GraphicsPath();
var firstFigure = new Figure();
firstFigure.AddShape(new EllipseShape(new RectangleF(350, 170, 570 - 350, 400 - 170)));
mask.AddFigure(firstFigure);
var options = new ContentAwareFillWatermarkOptions(mask)
{
MaxPaintingAttempts = 4
};
var result = WatermarkRemover.PaintOver(pngImage, options);
result.Save(outputPath);
}
The following example shows how to create a BMP image of the specified size.```csharp
[C#]
string dir = "c:\\temp\\";
// Create a BMP image 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100))
{
// Fill the image with a simple linear red-black gradient.
int width = bmpImage.Width;
int height = bmpImage.Height;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int hue = (255 * x) / width;
bmpImage.SetPixel(x, y, Aspose.Imaging.Color.FromArgb(255, hue, 0, 0));
}
}
using (System.IO.FileStream stream = new System.IO.FileStream(dir + "output.bmp", System.IO.FileMode.Create))
{
bmpImage.Save(stream);
}
}
The example shows how to export a BmpImage from a Png file while keeping the alpha channel, save a Bmp file with transparency.```csharp [C#]
string sourcePath = "input.png";
// Load a PNG image from a file.
using (Image pngImage = Image.Load(sourcePath))
{
// BMP image is saved with transparency support by default.
// If you want to explicitly specify such mode, the BmpOptions's Compression property should be set to BitmapCompression.Bitfields.
// The BitmapCompression.Bitfields compression method is the default compression method in the BmpOptions.
// So the same result of exporting a Bmp image with transparency can be achieved by either one of the following ways.
// With an implicit default options:
pngImage.Save(outputPath);
// With an explicit default options:
pngImage.Save(outputPath, new BmpOptions());
// Specifying the BitmapCompression.Bitfields compression method:
pngImage.Save(outputPath, new BmpOptions() { Compression = BitmapCompression.Bitfields });
}
## Constructors
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage__ctor_System_String_"></a> BmpImage\(string\)
Start using the BmpImage class effortlessly with this constructor that
initializes a new instance. Perfect for developers who want to get up and
running with Aspose.Imaging.FileFormats.Bmp.BmpImage objects quickly and efficiently.
```csharp
public BmpImage(string path)
Parameters
path
string
The path to load image from and initialize pixel and palette data with.
Examples
The example shows how to load a BmpImage from a file.```csharp [C#]
string dir = "c:\\temp\\";
// Load a BMP image from a file.
// The source pixels will be converted to 32-bpp format if required.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(dir + "sample.bmp"))
{
// Do some image processing.
// Save to another BMP file.
bmpImage.Save(dir + "sample.output.32bpp.bmp");
}
#### Exceptions
[ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)
The raster image is null.
[BmpImageException](/imaging/aspose.imaging.coreexceptions.imageformats.bmpimageexception)
The height must be positive.
[ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)
Palette must be specified for images with 8 bits per pixel or less.
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage__ctor_System_String_System_UInt16_Aspose_Imaging_FileFormats_Bmp_BitmapCompression_System_Double_System_Double_"></a> BmpImage\(string, ushort, BitmapCompression, double, double\)
Effortlessly create a new instance of the Aspose.Imaging.FileFormats.Bmp.BmpImage class with this constructor,
using specified parameters like path, bitsPerPixel, and compression. Ideal for developers
looking to initialize BmpImage objects quickly and efficiently, with precise control
over image characteristics.
```csharp
public BmpImage(string path, ushort bitsPerPixel, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
path
string
The path to load image from and initialize pixel and palette data with.
bitsPerPixel
ushort
The bits per pixel.
compression
BitmapCompression
The compression to use.
horizontalResolution
double
The horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
verticalResolution
double
The vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
Examples
The example shows how to load a BmpImage from a file with the specified bit depth and resolution.```csharp [C#]
string dir = "c:\\temp\\";
// Load a BMP image from a file.
// The source pixels will be converted to 24-bpp format if required.
// The resolution will be set to 96 dpi.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage =
new Aspose.Imaging.FileFormats.Bmp.BmpImage(dir + "sample.bmp", 24, Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb, 96.0, 96.0))
{
// Do some image processing.
// Save to another BMP file.
bmpImage.Save(dir + "sample.output.24bpp.96dpi.bmp");
}
#### Exceptions
[ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)
The raster image is null.
[BmpImageException](/imaging/aspose.imaging.coreexceptions.imageformats.bmpimageexception)
The height must be positive.
[ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)
Palette must be specified for images with 8 bits per pixel or less.
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage__ctor_System_IO_Stream_"></a> BmpImage\(Stream\)
Begin using the Aspose.Imaging.FileFormats.Bmp.BmpImage class effortlessly by initializing a new instance
with this constructor, using a stream as input. Perfect for developers seeking
a convenient way to work with BmpImage objects from various data sources,
ensuring flexibility and ease of integration.
```csharp
public BmpImage(Stream stream)
Parameters
stream
Stream
The stream to load image from and initialize pixel and palette data with.
Examples
The example shows how to load a BmpImage from a file stream.```csharp [C#]
string dir = "c:\\temp\\";
// Load a BMP image from a file stream.
// The source pixels will be converted to 32-bpp format if required.
using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.bmp"))
{
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(stream))
{
// Do some image processing.
// Save to another BMP file.
bmpImage.Save(dir + "sample.output.32bpp.bmp");
}
}
#### Exceptions
[ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)
The raster image is null.
[BmpImageException](/imaging/aspose.imaging.coreexceptions.imageformats.bmpimageexception)
The height must be positive.
[ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)
Palette must be specified for images with 8 bits per pixel or less.
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage__ctor_System_IO_Stream_System_UInt16_Aspose_Imaging_FileFormats_Bmp_BitmapCompression_System_Double_System_Double_"></a> BmpImage\(Stream, ushort, BitmapCompression, double, double\)
Start working with the Aspose.Imaging.FileFormats.Bmp.BmpImage class seamlessly by creating
a new instance using a stream, along with specified parameters like bitsPerPixel
and compression. Perfect for developers seeking a straightforward way to handle
BmpImage objects, ensuring flexibility and efficiency in their projects.
```csharp
public BmpImage(Stream stream, ushort bitsPerPixel, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
stream
Stream
The stream to load image from and initialize pixel and palette data with.
bitsPerPixel
ushort
The bits per pixel.
compression
BitmapCompression
The compression to use.
horizontalResolution
double
The horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
verticalResolution
double
The vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
Examples
The example shows how to load a BmpImage from a file stream with the specified bit depth and resolution.```csharp [C#]
string dir = "c:\\temp\\";
// Load a BMP image from a file stream.
// The source pixels will be converted to 24-bpp format if required.
// The resolution will be set to 96 dpi.
using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.bmp"))
{
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage =
new Aspose.Imaging.FileFormats.Bmp.BmpImage(stream, 24, Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb, 96.0, 96.0))
{
// Do some image processing.
// Save to another BMP file.
bmpImage.Save(dir + "sample.output.24bpp.96dpi.bmp");
}
}
#### Exceptions
[ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)
The raster image is null.
[BmpImageException](/imaging/aspose.imaging.coreexceptions.imageformats.bmpimageexception)
The height must be positive.
[ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)
Palette must be specified for images with 8 bits per pixel or less.
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage__ctor_Aspose_Imaging_RasterImage_"></a> BmpImage\(RasterImage\)
Effortlessly create a new instance of the Aspose.Imaging.FileFormats.Bmp.BmpImage class
by initializing it with a RasterImage object. Perfect for developers looking
to seamlessly convert existing raster images to the BmpImage format, ensuring
compatibility and ease of integration into their projects.
```csharp
public BmpImage(RasterImage rasterImage)
Parameters
rasterImage
RasterImage
The image to initialize pixel and palette data with.
Examples
The example shows how to load a BmpImage from another instance of RasterImage.```csharp [C#]
string dir = "c:\\temp\\";
// Create a new PNG image.
Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), true);
using (Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Create(createOptions, 100, 100))
{
// Fill the entire PNG image in red.
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(rasterImage);
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(brush, rasterImage.Bounds);
// Create a BMP image based on the PNG image.
// The source pixels will be converted to 32-bpp format if required.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(rasterImage))
{
// Save to a BMP file
bmpImage.Save(dir + "output.32bpp.bmp");
}
}
#### Exceptions
[ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)
The raster image is null.
[BmpImageException](/imaging/aspose.imaging.coreexceptions.imageformats.bmpimageexception)
The height must be positive.
[ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)
Palette must be specified for images with 8 bits per pixel or less.
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage__ctor_Aspose_Imaging_RasterImage_System_UInt16_Aspose_Imaging_FileFormats_Bmp_BitmapCompression_System_Double_System_Double_"></a> BmpImage\(RasterImage, ushort, BitmapCompression, double, double\)
Start working with the Aspose.Imaging.FileFormats.Bmp.BmpImage class seamlessly by creating a new instance
using a rasterImage along with specified parameters like bitsPerPixel and compression.
Perfect for developers seeking a straightforward way to handle BmpImage objects,
ensuring flexibility and efficiency in their projects.
```csharp
public BmpImage(RasterImage rasterImage, ushort bitsPerPixel, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
rasterImage
RasterImage
The image to initialize pixel and palette data with.
bitsPerPixel
ushort
The bits per pixel.
compression
BitmapCompression
The compression to use.
horizontalResolution
double
The horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
verticalResolution
double
The vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
Examples
The example shows how to load a BmpImage from another instance of RasterImage with the specified bit depth and compression.```csharp [C#]
string dir = "c:\\temp\\";
// Create a new PNG image.
Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), true);
using (Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Create(createOptions, 100, 100))
{
// Fill the entire PNG image in red.
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(rasterImage);
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(brush, rasterImage.Bounds);
// Create a BMP image based on the PNG image.
// The source pixels will be converted to 24-bpp format if required.
// The resolution will be set to 96 dpi.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(rasterImage, 24, Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb, 96.0, 96.0))
{
// Save to a BMP file
bmpImage.Save(dir + "output.24bpp.96dpi.bmp");
}
}
#### Exceptions
[ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)
The raster image is null.
[BmpImageException](/imaging/aspose.imaging.coreexceptions.imageformats.bmpimageexception)
The height must be positive.
[ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)
Palette must be specified for images with 8 bits per pixel or less.
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage__ctor_System_Int32_System_Int32_"></a> BmpImage\(int, int\)
Start using the Aspose.Imaging.FileFormats.Bmp.BmpImage class effortlessly by creating a new instance
with specified width and height parameters. Ideal for developers seeking
a convenient way to generate BmpImage objects of custom dimensions, ensuring
flexibility and ease of integration into their projects.
```csharp
public BmpImage(int width, int height)
Parameters
width
int
The image width.
height
int
The image height.
Examples
The example shows how to create a BmpImage of the specified size.```csharp [C#]
string dir = "c:\\temp\\";
// Create a 32-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100))
{
// Fill the entire image in red.
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(brush, bmpImage.Bounds);
// Save to a BMP file
bmpImage.Save(dir + "output.bmp");
}
The following example shows how to palletize a BMP image to reduce its output size.```csharp
[C#]
// Create a BMP image 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100))
{
// The linear gradient from the left-top to the right-bottom corner of the image.
Aspose.Imaging.Brushes.LinearGradientBrush brush =
new Aspose.Imaging.Brushes.LinearGradientBrush(
new Aspose.Imaging.Point(0, 0),
new Aspose.Imaging.Point(bmpImage.Width, bmpImage.Height),
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green);
// Fill the entire image with the linear gradient brush.
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
gr.FillRectangle(brush, bmpImage.Bounds);
// Get the closest 8-bit color palette which covers as many pixels as possible, so that a palettized image
// is almost visually indistinguishable from a non-palletized one.
Aspose.Imaging.IColorPalette palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette(bmpImage, 256);
// 8-bit palette contains at most 256 colors.
Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
saveOptions.Palette = palette;
saveOptions.BitsPerPixel = 8;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream, saveOptions);
System.Console.WriteLine("The palettized image size is {0} bytes.", stream.Length);
}
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("The non-palettized image size is {0} bytes.", stream.Length);
}
}
// The output looks like this:
// The palettized image size is 11078 bytes.
// The non-palettized image size is 40054 bytes.
Exceptions
The height must be positive.
Palette must be specified for images with 8 bits per pixel or less.
BmpImage(int, int, ushort, IColorPalette)
Begin using the Aspose.Imaging.FileFormats.Bmp.BmpImage class seamlessly by initializing a new instance with parameters such as width, height, bit depth, and palette. Perfect for developers seeking a straightforward way to create BmpImage objects with custom dimensions and color configurations, ensuring flexibility and efficiency in their projects.
public BmpImage(int width, int height, ushort bitsPerPixel, IColorPalette palette)
Parameters
width
int
The image width.
height
int
The image height.
bitsPerPixel
ushort
The bits per pixel.
palette
IColorPalette
The color palette.
Examples
The example shows how to create a BmpImage of the specified size with the specified palette.```csharp [C#]
string dir = "c:\\temp\\";
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
// Create a monochrome 1-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 1, palette))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the upper half of the image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, new Aspose.Imaging.Rectangle(0, 0, bmpImage.Width, bmpImage.Height / 2));
// Fill the lower half of the image in green.
Aspose.Imaging.Brushes.SolidBrush greenBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Green);
gr.FillRectangle(greenBrush, new Aspose.Imaging.Rectangle(0, bmpImage.Height / 2, bmpImage.Width, bmpImage.Height / 2));
// Save to BMP
bmpImage.Save(dir + "output.monochrome.bmp");
}
#### Exceptions
[BmpImageException](/imaging/aspose.imaging.coreexceptions.imageformats.bmpimageexception)
The height must be positive.
[ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)
Palette must be specified for images with 8 bits per pixel or less.
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage__ctor_System_Int32_System_Int32_System_UInt16_Aspose_Imaging_IColorPalette_Aspose_Imaging_FileFormats_Bmp_BitmapCompression_System_Double_System_Double_"></a> BmpImage\(int, int, ushort, IColorPalette, BitmapCompression, double, double\)
Effortlessly create a new instance of the Aspose.Imaging.FileFormats.Bmp.BmpImage class with this constructor,
specifying parameters like width, height, bitsPerPixel, and palette. Perfect for developers
seeking a convenient way to generate BmpImage objects with custom dimensions
and color configurations, ensuring flexibility and ease of integration into their projects.
```csharp
public BmpImage(int width, int height, ushort bitsPerPixel, IColorPalette palette, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
width
int
The image width.
height
int
The image height.
bitsPerPixel
ushort
The bits per pixel.
palette
IColorPalette
The color palette.
compression
BitmapCompression
The compression to use.
horizontalResolution
double
The horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
verticalResolution
double
The vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
Examples
The example shows how to create a BmpImage using various options.```csharp [C#]
string dir = "c:\\temp\\";
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
// Create a monochrome 1-bpp BMP image of 100 x 100 px.
// The horizontal and vertical resolution will be set to 96 dpi.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 1, palette, Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb, 96.0, 96.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the upper half of the image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, new Aspose.Imaging.Rectangle(0, 0, bmpImage.Width, bmpImage.Height / 2));
// Fill the lower half of the image in green.
Aspose.Imaging.Brushes.SolidBrush greenBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Green);
gr.FillRectangle(greenBrush, new Aspose.Imaging.Rectangle(0, bmpImage.Height / 2, bmpImage.Width, bmpImage.Height / 2));
// Save to a BMP file
bmpImage.Save(dir + "output.monochrome.96dpi.bmp");
}
#### Exceptions
[BmpImageException](/imaging/aspose.imaging.coreexceptions.imageformats.bmpimageexception)
The height must be positive.
[ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)
Palette must be specified for images with 8 bits per pixel or less.
## Properties
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage_BitmapInfoHeader"></a> BitmapInfoHeader
Quickly access essential details about your bitmap image with this straightforward function.
Perfect for developers needing to retrieve header information for their images.
```csharp
public BitmapInfoHeader BitmapInfoHeader { get; }
Property Value
Examples
The following example gets the information from the BMP header and prints it to the console.```csharp [C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
Aspose.Imaging.FileFormats.Bmp.BitmapInfoHeader header = bmpImage.BitmapInfoHeader;
System.Console.WriteLine("The number of palette colors that are required for displaying the bitmap: {0}", header.BitmapColorsImportant);
System.Console.WriteLine("The number of palette colors used in the bitmap: {0}", header.BitmapColorsUsed);
System.Console.WriteLine("The bitmap compression: {0}", header.BitmapCompression);
System.Console.WriteLine("The bitmap height: {0}", header.BitmapHeight);
System.Console.WriteLine("The bitmap width: {0}", header.BitmapWidth);
System.Console.WriteLine("The bitmap raw data size in bytes: {0}", header.BitmapImageSize);
System.Console.WriteLine("The number of planes: {0}", header.BitmapPlanes);
System.Console.WriteLine("The horizontal resolution of the bitmap, in pixels-per-meter: {0}", header.BitmapXPelsPerMeter);
System.Console.WriteLine("The vertical resolution of the bitmap, in pixels-per-meter: {0}", header.BitmapYPelsPerMeter);
System.Console.WriteLine("The number of bits per pixel: {0}", header.BitsPerPixel);
System.Console.WriteLine("The extra bits masks: {0}", header.ExtraBitMasks);
System.Console.WriteLine("The header size in bytes: {0}", header.HeaderSize);
}
//The output may look like this:
//The number of palette colors that are required for displaying the bitmap: 0
//The number of palette colors used in the bitmap: 0
//The bitmap compression: 0
//The bitmap height: 375
//The bitmap width: 500
//The bitmap raw data size in bytes: 562500
//The number of planes: 1
//The horizontal resolution of the bitmap, in pixels-per-meter: 0
//The vertical resolution of the bitmap, in pixels-per-meter: 0
//The number of bits per pixel: 24
//The extra bits masks:
//The header size in bytes: 40
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage_BitsPerPixel"></a> BitsPerPixel
Access the number of bits per pixel for the image with ease using this property.
Perfect for developers seeking quick information about image quality and depth.
```csharp
public override int BitsPerPixel { get; }
Property Value
Examples
The following example gets the general information about the image including pixel format, image size, resolution, compression etc.```csharp [C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
The following example shows how the bitmap compression affects the output image size.```csharp
[C#]
Aspose.Imaging.FileFormats.Bmp.BitmapCompression[] compressions = new Aspose.Imaging.FileFormats.Bmp.BitmapCompression[]
{
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb,
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rle8,
};
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
foreach (Aspose.Imaging.FileFormats.Bmp.BitmapCompression compression in compressions)
{
// Create a 8-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the entire image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, bmpImage.Bounds);
// Save the image to a stream to get the output image size.
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("---------------------------------------------");
System.Console.WriteLine("The compression={0}", bmpImage.Compression);
System.Console.WriteLine("The number of bits per pixel={0}", bmpImage.BitsPerPixel);
System.Console.WriteLine("The image dimensions={0} x {1}", bmpImage.Width, bmpImage.Height);
System.Console.WriteLine("The raw line size={0}", bmpImage.RawLineSize);
System.Console.WriteLine("The output size in bytes={0}", stream.Length);
}
}
}
// The output looks like this:
// ---------------------------------------------
// The compression = Rgb
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 11078
// ---------------------------------------------
// The compression = Rle8
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 856
Compression
Retrieve the compression type used for the image effortlessly with this property. Perfect for developers needing to quickly access information about image compression.
public BitmapCompression Compression { get; }
Property Value
Examples
The following example gets the general information about the image including pixel format, image size, resolution, compression etc.```csharp [C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
The following example shows how the bitmap compression affects the output image size.```csharp
[C#]
Aspose.Imaging.FileFormats.Bmp.BitmapCompression[] compressions = new Aspose.Imaging.FileFormats.Bmp.BitmapCompression[]
{
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb,
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rle8,
};
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
foreach (Aspose.Imaging.FileFormats.Bmp.BitmapCompression compression in compressions)
{
// Create a 8-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the entire image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, bmpImage.Bounds);
// Save the image to a stream to get the output image size.
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("---------------------------------------------");
System.Console.WriteLine("The compression={0}", bmpImage.Compression);
System.Console.WriteLine("The number of bits per pixel={0}", bmpImage.BitsPerPixel);
System.Console.WriteLine("The image dimensions={0} x {1}", bmpImage.Width, bmpImage.Height);
System.Console.WriteLine("The raw line size={0}", bmpImage.RawLineSize);
System.Console.WriteLine("The output size in bytes={0}", stream.Length);
}
}
}
// The output looks like this:
// ---------------------------------------------
// The compression = Rgb
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 11078
// ---------------------------------------------
// The compression = Rle8
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 856
FileFormat
Easily retrieve the file format value with this user-friendly property. Ideal for developers seeking quick access to information about the file format.
public override FileFormat FileFormat { get; }
Property Value
Examples
The following example shows how to extract information about raw data format and alpha channel from a BMP image.```csharp [C#]
// Create a 32-bpp BMP image of 100 x 100 px.
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);
};
// Create a 24-bpp BMP image of 100 x 100 px.
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);
};
// Generally, BMP doesn't support alpha channel so the output will look like this:
// FileFormat = Bmp, RawDataFormat = Rgb32Bpp, used channels: 8,8,8,8, HasAlpha = False
// FileFormat = Bmp, RawDataFormat = Rgb24Bpp, used channels: 8,8,8, HasAlpha = False
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage_HasAlpha"></a> HasAlpha
Gets a value indicating whether this instance has alpha.
```csharp
public override bool HasAlpha { get; }
Property Value
Height
Retrieve the height of the image effortlessly with this property. Ideal for developers needing quick access to information about image dimensions.
public override int Height { get; }
Property Value
Examples
The following example gets the general information about the image including pixel format, image size, resolution, compression etc.```csharp [C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
The following example shows how the bitmap compression affects the output image size.```csharp
[C#]
Aspose.Imaging.FileFormats.Bmp.BitmapCompression[] compressions = new Aspose.Imaging.FileFormats.Bmp.BitmapCompression[]
{
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb,
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rle8,
};
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
foreach (Aspose.Imaging.FileFormats.Bmp.BitmapCompression compression in compressions)
{
// Create a 8-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the entire image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, bmpImage.Bounds);
// Save the image to a stream to get the output image size.
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("---------------------------------------------");
System.Console.WriteLine("The compression={0}", bmpImage.Compression);
System.Console.WriteLine("The number of bits per pixel={0}", bmpImage.BitsPerPixel);
System.Console.WriteLine("The image dimensions={0} x {1}", bmpImage.Width, bmpImage.Height);
System.Console.WriteLine("The raw line size={0}", bmpImage.RawLineSize);
System.Console.WriteLine("The output size in bytes={0}", stream.Length);
}
}
}
// The output looks like this:
// ---------------------------------------------
// The compression = Rgb
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 11078
// ---------------------------------------------
// The compression = Rle8
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 856
HorizontalResolution
This property allows you to easily get or set the horizontal resolution, measured in pixels per inch, of the Aspose.Imaging.RasterImage object. Ideal for developers needing precise control over image resolution for their applications.
public override double HorizontalResolution { get; set; }
Property Value
Examples
The following example shows how to set horizontal/vertical resolution of a BMP image.```csharp [C#]
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
// Get horizontal and vertical resolution of the BmpImage
double horizontalResolution = bmpImage.HorizontalResolution;
double verticalResolution = bmpImage.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)
{
// Use the SetResolution method for updating both resolution values in a single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 0
// The vertical resolution, in pixels per inch: 0
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96.012
// The vertical resolution, in pixels per inch: 96.012
}
The following example gets the general information about the image including pixel format, image size, resolution, compression etc.```csharp
[C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
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.
RawDataFormat
Easily obtain the format of your raw data with this user-friendly function. Perfect for developers looking to quickly access crucial information about their data format.
public override PixelDataFormat RawDataFormat { get; }
Property Value
Examples
The following example shows how to extract information about raw data format and alpha channel from a BMP image.```csharp [C#]
// Create a 32-bpp BMP image of 100 x 100 px.
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);
};
// Create a 24-bpp BMP image of 100 x 100 px.
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);
};
// Generally, BMP doesn't support alpha channel so the output will look like this:
// FileFormat = Bmp, RawDataFormat = Rgb32Bpp, used channels: 8,8,8,8, HasAlpha = False
// FileFormat = Bmp, RawDataFormat = Rgb24Bpp, used channels: 8,8,8, HasAlpha = False
The following example gets the general information about the image including pixel format, image size, resolution, compression etc.```csharp
[C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
RawLineSize
Quickly access the size of each raw line in bytes with this straightforward property. Ideal for developers needing to efficiently handle raw image data.
public override int RawLineSize { get; }
Property Value
Examples
The following example gets the general information about the image including pixel format, image size, resolution, compression etc.```csharp [C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
The following example shows how the bitmap compression affects the output image size.```csharp
[C#]
Aspose.Imaging.FileFormats.Bmp.BitmapCompression[] compressions = new Aspose.Imaging.FileFormats.Bmp.BitmapCompression[]
{
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb,
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rle8,
};
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
foreach (Aspose.Imaging.FileFormats.Bmp.BitmapCompression compression in compressions)
{
// Create a 8-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the entire image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, bmpImage.Bounds);
// Save the image to a stream to get the output image size.
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("---------------------------------------------");
System.Console.WriteLine("The compression={0}", bmpImage.Compression);
System.Console.WriteLine("The number of bits per pixel={0}", bmpImage.BitsPerPixel);
System.Console.WriteLine("The image dimensions={0} x {1}", bmpImage.Width, bmpImage.Height);
System.Console.WriteLine("The raw line size={0}", bmpImage.RawLineSize);
System.Console.WriteLine("The output size in bytes={0}", stream.Length);
}
}
}
// The output looks like this:
// ---------------------------------------------
// The compression = Rgb
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 11078
// ---------------------------------------------
// The compression = Rle8
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 856
VerticalResolution
Easily retrieve or set the vertical resolution, measured in pixels per inch, of this Aspose.Imaging.RasterImage object with this property. Perfect for developers requiring precise control over image resolution in their applications.
public override double VerticalResolution { get; set; }
Property Value
Examples
The following example shows how to set horizontal/vertical resolution of a BMP image.```csharp [C#]
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
// Get horizontal and vertical resolution of the BmpImage
double horizontalResolution = bmpImage.HorizontalResolution;
double verticalResolution = bmpImage.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)
{
// Use the SetResolution method for updating both resolution values in a single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 0
// The vertical resolution, in pixels per inch: 0
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96.012
// The vertical resolution, in pixels per inch: 96.012
}
The following example gets the general information about the image including pixel format, image size, resolution, compression etc.```csharp
[C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
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.
Width
Access the width of the image easily with this property. Ideal for developers seeking quick information about the image dimensions.
public override int Width { get; }
Property Value
Examples
The following example gets the general information about the image including pixel format, image size, resolution, compression etc.```csharp [C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
The following example shows how the bitmap compression affects the output image size.```csharp
[C#]
Aspose.Imaging.FileFormats.Bmp.BitmapCompression[] compressions = new Aspose.Imaging.FileFormats.Bmp.BitmapCompression[]
{
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb,
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rle8,
};
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
foreach (Aspose.Imaging.FileFormats.Bmp.BitmapCompression compression in compressions)
{
// Create a 8-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the entire image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, bmpImage.Bounds);
// Save the image to a stream to get the output image size.
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("---------------------------------------------");
System.Console.WriteLine("The compression={0}", bmpImage.Compression);
System.Console.WriteLine("The number of bits per pixel={0}", bmpImage.BitsPerPixel);
System.Console.WriteLine("The image dimensions={0} x {1}", bmpImage.Width, bmpImage.Height);
System.Console.WriteLine("The raw line size={0}", bmpImage.RawLineSize);
System.Console.WriteLine("The output size in bytes={0}", stream.Length);
}
}
}
// The output looks like this:
// ---------------------------------------------
// The compression = Rgb
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 11078
// ---------------------------------------------
// The compression = Rle8
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 856
Methods
GetDefaultOptions(object[])
Retrieve the default options effortlessly with this straightforward method. Ideal for developers seeking quick access to default image settings or configurations.
public override ImageOptionsBase GetDefaultOptions(object[] args)
Parameters
args
object[]
The arguments.
Returns
Default options
OnCached()
Called when data is cached and all related resources may be de-allocated.
protected override void OnCached()
OnPaletteChanging(IColorPalette, IColorPalette)
Called when palette is changing.
protected override void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)
Parameters
oldPalette
IColorPalette
The old palette.
newPalette
IColorPalette
The new palette.
SaveData(Stream)
Saves the data.
protected override void SaveData(Stream stream)
Parameters
stream
Stream
The stream to save data to.
SetResolution(double, double)
Adjust the resolution of your Aspose.Imaging.RasterImage effortlessly with this user-friendly method. Perfect for developers seeking precise control over image resolution in their applications.
public override 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 BMP image.```csharp [C#]
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
// Get horizontal and vertical resolution of the BmpImage
double horizontalResolution = bmpImage.HorizontalResolution;
double verticalResolution = bmpImage.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)
{
// Use the SetResolution method for updating both resolution values in a single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 0
// The vertical resolution, in pixels per inch: 0
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96.012
// The vertical resolution, in pixels per inch: 96.012
}
The following example gets the general information about the image including pixel format, image size, resolution, compression etc.```csharp
[C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
ToBitmap()
Easily convert your raster image to a bitmap with this simple method. Perfect for developers needing to seamlessly transition between different image formats.
public override Bitmap ToBitmap()
Returns
The bitmap
Examples
The following example converts a BMP image to a GDI bitmap.```csharp [C#]
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Drawing.Bitmap bitmap = bmpImage.ToBitmap();
// Process the GDI bitmap.
}
### <a id="Aspose_Imaging_FileFormats_Bmp_BmpImage_UpdateDimensions_System_Int32_System_Int32_"></a> UpdateDimensions\(int, int\)
Updates the image dimensions.
```csharp
protected override void UpdateDimensions(int newWidth, int newHeight)
Parameters
newWidth
int
The new image width.
newHeight
int
The new image height.