Class BmpImage
Nombre del espacio: Aspose.Imaging.FileFormats.Bmp Asamblea: Aspose.Imaging.dll (25.4.0)
Usted puede manejar sin esfuerzo Bitmap (BMP) y Device Independent Bitmap(DIB) archivos, facilitando la manipulación y procesamiento eficientes de rasterPerforman varias operaciones en las imágenes, esta API simplifica laflujo de trabajo, ofreciendo a los desarrolladores un conjunto de herramientas fiable para trabajar con BMP yFormatos DIB en sus aplicaciones de software.
[JsonObject(MemberSerialization.OptIn)]
public sealed class BmpImage : RasterCachedImage, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata
Inheritance
object ← DisposableObject ← DataStreamSupporter ← Image ← RasterImage ← RasterCachedImage ← BmpImage
Implements
IDisposable ,y, IObjectWithBounds ,y, IRasterImageArgb32PixelLoader ,y, IRasterImageRawDataLoader ,y, IHasXmpData ,y, IHasMetadata
Miembros heredados
RasterCachedImage.CacheData() ,y, RasterCachedImage.Blend(Point, RasterImage, Rectangle, byte) ,y, RasterCachedImage.Resize(int, int, ResizeType) ,y, RasterCachedImage.Resize(int, int, ImageResizeSettings) ,y, RasterCachedImage.RotateFlip(RotateFlipType) ,y, RasterCachedImage.Rotate(float, bool, Color) ,y, RasterCachedImage.Crop(Rectangle) ,y, RasterCachedImage.Dither(DitheringMethod, int, IColorPalette) ,y, RasterCachedImage.Grayscale() ,y, RasterCachedImage.NormalizeHistogram() ,y, RasterCachedImage.BinarizeFixed(byte) ,y, RasterCachedImage.BinarizeOtsu() ,y, RasterCachedImage.BinarizeBradley(double, int) ,y, RasterCachedImage.BinarizeBradley(double) ,y, RasterCachedImage.AdjustBrightness(int) ,y, RasterCachedImage.AdjustContrast(float) ,y, RasterCachedImage.AdjustGamma(float, float, float) ,y, RasterCachedImage.AdjustGamma(float) ,y, RasterCachedImage.IsCached ,y, RasterImage.RemoveMetadata() ,y, RasterImage.Save(Stream, ImageOptionsBase, Rectangle) ,y, RasterImage.GetModifyDate(bool) ,y, RasterImage.Dither(DitheringMethod, int) ,y, RasterImage.Dither(DitheringMethod, int, IColorPalette) ,y, RasterImage.GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader) ,y, RasterImage.GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings) ,y, RasterImage.GetDefaultArgb32Pixels(Rectangle) ,y, RasterImage.GetDefaultRawData(Rectangle, RawDataSettings) ,y, RasterImage.GetArgb32Pixel(int, int) ,y, RasterImage.GetPixel(int, int) ,y, RasterImage.SetArgb32Pixel(int, int, int) ,y, RasterImage.SetPixel(int, int, Color) ,y, RasterImage.ReadScanLine(int) ,y, RasterImage.ReadArgb32ScanLine(int) ,y, RasterImage.WriteScanLine(int, Color[]) ,y, RasterImage.WriteArgb32ScanLine(int, int[]) ,y, RasterImage.LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader) ,y, RasterImage.LoadPartialPixels(Rectangle, IPartialPixelLoader) ,y, RasterImage.LoadArgb32Pixels(Rectangle) ,y, RasterImage.LoadArgb64Pixels(Rectangle) ,y, RasterImage.LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader) ,y, RasterImage.LoadPixels(Rectangle) ,y, RasterImage.LoadCmykPixels(Rectangle) ,y, RasterImage.LoadCmyk32Pixels(Rectangle) ,y, RasterImage.LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader) ,y, RasterImage.LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader) ,y, RasterImage.SaveRawData(byte[], int, Rectangle, RawDataSettings) ,y, RasterImage.SaveArgb32Pixels(Rectangle, int[]) ,y, RasterImage.SavePixels(Rectangle, Color[]) ,y, RasterImage.SaveCmykPixels(Rectangle, CmykColor[]) ,y, RasterImage.SaveCmyk32Pixels(Rectangle, int[]) ,y, RasterImage.SetResolution(double, double) ,y, RasterImage.SetPalette(IColorPalette, bool) ,y, RasterImage.Resize(int, int, ImageResizeSettings) ,y, RasterImage.Rotate(float, bool, Color) ,y, RasterImage.Rotate(float) ,y, RasterImage.BinarizeFixed(byte) ,y, RasterImage.BinarizeOtsu() ,y, RasterImage.BinarizeBradley(double) ,y, RasterImage.BinarizeBradley(double, int) ,y, RasterImage.Blend(Point, RasterImage, Rectangle, byte) ,y, RasterImage.Blend(Point, RasterImage, byte) ,y, RasterImage.Grayscale() ,y, RasterImage.NormalizeHistogram() ,y, RasterImage.AdjustBrightness(int) ,y, RasterImage.AdjustContrast(float) ,y, RasterImage.AdjustGamma(float, float, float) ,y, RasterImage.AdjustGamma(float) ,y, RasterImage.GetSkewAngle() ,y, RasterImage.NormalizeAngle() ,y, RasterImage.NormalizeAngle(bool, Color) ,y, RasterImage.Filter(Rectangle, FilterOptionsBase) ,y, RasterImage.ReplaceColor(Color, byte, Color) ,y, RasterImage.ReplaceColor(int, byte, int) ,y, RasterImage.ReplaceNonTransparentColors(Color) ,y, RasterImage.ReplaceNonTransparentColors(int) ,y, RasterImage.ToBitmap() ,y, RasterImage.PremultiplyComponents ,y, RasterImage.UseRawData ,y, RasterImage.UpdateXmpData ,y, RasterImage.XmpData ,y, RasterImage.RawIndexedColorConverter ,y, RasterImage.RawCustomColorConverter ,y, RasterImage.RawFallbackIndex ,y, RasterImage.RawDataSettings ,y, RasterImage.UsePalette ,y, RasterImage.RawDataFormat ,y, RasterImage.RawLineSize ,y, RasterImage.IsRawDataAvailable ,y, RasterImage.HorizontalResolution ,y, RasterImage.VerticalResolution ,y, RasterImage.HasTransparentColor ,y, RasterImage.HasAlpha ,y, RasterImage.TransparentColor ,y, RasterImage.ImageOpacity ,y, Image.CanLoad(string) ,y, Image.CanLoad(string, LoadOptions) ,y, Image.CanLoad(Stream) ,y, Image.CanLoad(Stream, LoadOptions) ,y, Image.Create(ImageOptionsBase, int, int) ,y, Image.Create(Image[]) ,y, Image.Create(MultipageCreateOptions) ,y, Image.Create(string[], bool) ,y, Image.Create(string[]) ,y, Image.Create(Image[], bool) ,y, Image.GetFileFormat(string) ,y, Image.GetFileFormat(Stream) ,y, Image.GetFittingRectangle(Rectangle, int, int) ,y, Image.GetFittingRectangle(Rectangle, int[], int, int) ,y, Image.Load(string, LoadOptions) ,y, Image.Load(string) ,y, Image.Load(Stream, LoadOptions) ,y, Image.Load(Stream) ,y, Image.GetProportionalWidth(int, int, int) ,y, Image.GetProportionalHeight(int, int, int) ,y, Image.RemoveMetadata() ,y, Image.CanSave(ImageOptionsBase) ,y, Image.Resize(int, int) ,y, Image.Resize(int, int, ResizeType) ,y, Image.Resize(int, int, ImageResizeSettings) ,y, Image.GetDefaultOptions(object[]) ,y, Image.GetOriginalOptions() ,y, Image.ResizeWidthProportionally(int) ,y, Image.ResizeHeightProportionally(int) ,y, Image.ResizeWidthProportionally(int, ResizeType) ,y, Image.ResizeHeightProportionally(int, ResizeType) ,y, Image.ResizeWidthProportionally(int, ImageResizeSettings) ,y, Image.ResizeHeightProportionally(int, ImageResizeSettings) ,y, Image.RotateFlip(RotateFlipType) ,y, Image.Rotate(float) ,y, Image.Crop(Rectangle) ,y, Image.Crop(int, int, int, int) ,y, Image.Save() ,y, Image.Save(string) ,y, Image.Save(string, ImageOptionsBase) ,y, Image.Save(string, ImageOptionsBase, Rectangle) ,y, Image.Save(Stream, ImageOptionsBase) ,y, Image.Save(Stream, ImageOptionsBase, Rectangle) ,y, Image.GetSerializedStream(ImageOptionsBase, Rectangle, out int) ,y, Image.SetPalette(IColorPalette, bool) ,y, Image.BitsPerPixel ,y, Image.Bounds ,y, Image.Container ,y, Image.Height ,y, Image.Palette ,y, Image.UsePalette ,y, Image.Size ,y, Image.Width ,y, Image.InterruptMonitor ,y, Image.BufferSizeHint ,y, Image.AutoAdjustPalette ,y, Image.HasBackgroundColor ,y, Image.FileFormat ,y, Image.BackgroundColor ,y, DataStreamSupporter.CacheData() ,y, DataStreamSupporter.Save() ,y, DataStreamSupporter.Save(Stream) ,y, DataStreamSupporter.Save(string) ,y, DataStreamSupporter.Save(string, bool) ,y, DataStreamSupporter.DataStreamContainer ,y, DataStreamSupporter.IsCached ,y, DisposableObject.Dispose() ,y, DisposableObject.Disposed ,y, object.GetType() ,y, object.ToString() ,y, object.Equals(object?) ,y, object.Equals(object?, object?) ,y, object.ReferenceEquals(object?, object?) ,y, object.GetHashCode()
Examples
Descomprimir la imagen BMP que anteriormente fue comprimida utilizando el algoritmo de compresión DXT1.
using (var image = Image.Load("CompressedTiger.bmp"))
{
image.Save("DecompressedTiger.bmp", new BmpOptions());
}
Comprimir la imagen BMP utilizando el algoritmo de compresión DXT1.
using (var image = Image.Load("Tiger.bmp"))
{
image.Save("CompressedTiger.bmp", new BmpOptions { Compression = BitmapCompression.Dxt1 });
}
El ejemplo muestra cómo eliminar cualquier objeto de la imagen utilizando Path de gráficos con el algoritmo de Telea.
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);
}
El ejemplo muestra cómo exportar un BmpImage con el tipo de compresión Rgb.
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 });
}
El ejemplo muestra cómo eliminar cualquier objeto de la imagen utilizando Path de gráficos con el algoritmo de relleno de contenido.
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);
}
El siguiente ejemplo muestra cómo crear una imagen BMP del tamaño especificado.
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);
}
}
El ejemplo muestra cómo exportar un BmpImage de un archivo Png mientras se mantiene el canal alfa, guardando un archivo Bmp con transparencia.
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
BmpImage(El string)
Comience usando la clase BmpImage sin esfuerzo con este constructor queInicializa una nueva instancia. Perfecto para los desarrolladores que quieren subir yejecutar con Aspose.Imaging.FileFormats.Bmp.BmpImage objetos de forma rápida y eficiente.
public BmpImage(string path)
Parameters
path
string
El camino para cargar la imagen y iniciar los datos de píxeles y paletas con.
Examples
El ejemplo muestra cómo cargar un BmpImage de un archivo.
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
La imagen del raster es nula.
La altura debe ser positiva.
La paleta debe ser especificada para imágenes con 8 bits por pixel o menos.
BmpImage(Tamaño, Tamaño, Tamaño, Tamaño, Tamaño)
Crea sin esfuerzo una nueva instancia de la clase Aspose.Imaging.FileFormats.Bmp.BmpImage con este constructor,utilizando parámetros especificados como el camino, bitsPerPixel, y la compresión.Buscando iniciar objetos BmpImage de forma rápida y eficiente, con control precisosobre las características de la imagen.
public BmpImage(string path, ushort bitsPerPixel, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
path
string
El camino para cargar la imagen y iniciar los datos de píxeles y paletas con.
bitsPerPixel
ushort
Los bits por pixel.
compression
BitmapCompression
La composición para usar.
horizontalResolution
double
La resolución horizontal. Nota debido a la rotación la resolución resultante puede diferir ligeramente de la pasada.
verticalResolution
double
La resolución vertical. Nota debido a la rotación la resolución resultante puede diferir ligeramente de la pasada.
Examples
El ejemplo muestra cómo cargar un BmpImage de un archivo con la profundidad y resolución de bit especificados.
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
La imagen del raster es nula.
La altura debe ser positiva.
La paleta debe ser especificada para imágenes con 8 bits por pixel o menos.
BmpImage(Stream)
Comience utilizando la clase Aspose.Imaging.FileFormats.Bmp.BmpImage sin esfuerzo iniciando una nueva instanciacon este constructor, utilizando un flujo como entrada. Perfecto para los desarrolladores que buscanuna forma conveniente de trabajar con objetos BmpImage de diferentes fuentes de datos,garantizar la flexibilidad y la facilidad de la integración.
public BmpImage(Stream stream)
Parameters
stream
Stream
El flujo para cargar la imagen y iniciar los datos de píxeles y paletas con.
Examples
El ejemplo muestra cómo cargar un BmpImage de un flujo de archivos.
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
La imagen del raster es nula.
La altura debe ser positiva.
La paleta debe ser especificada para imágenes con 8 bits por pixel o menos.
BmpImage(Stream, ushort, BitmapCompression, doble, doble)
Comience trabajando con Aspose.Imaging.FileFormats.Bmp.BmpImage clase sin sentido creandouna nueva instancia utilizando un flujo, junto con los parámetros especificados como bitsPerPixelPerfecto para los desarrolladores que buscan una forma sencilla de gestionarObjetos BmpImage, garantizando la flexibilidad y la eficiencia en sus proyectos.
public BmpImage(Stream stream, ushort bitsPerPixel, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
stream
Stream
El flujo para cargar la imagen y iniciar los datos de píxeles y paletas con.
bitsPerPixel
ushort
Los bits por pixel.
compression
BitmapCompression
La composición para usar.
horizontalResolution
double
La resolución horizontal. Nota debido a la rotación la resolución resultante puede diferir ligeramente de la pasada.
verticalResolution
double
La resolución vertical. Nota debido a la rotación la resolución resultante puede diferir ligeramente de la pasada.
Examples
El ejemplo muestra cómo cargar un BmpImage de un flujo de archivos con la profundidad y resolución de bit especificados.
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
La imagen del raster es nula.
La altura debe ser positiva.
La paleta debe ser especificada para imágenes con 8 bits por pixel o menos.
BmpImage(RasterImage)
Crea sin esfuerzo una nueva instancia de la clase Aspose.Imaging.FileFormats.Bmp.BmpImageInicializándolo con un objeto RasterImage. Perfecto para los desarrolladores que buscanConvertir las imágenes de raster existentes en el formato BmpImage, garantizandoCompatibilidad y facilidad de integración en sus proyectos.
public BmpImage(RasterImage rasterImage)
Parameters
rasterImage
RasterImage
La imagen para iniciar los pixel y los datos de paleta con.
Examples
El ejemplo muestra cómo cargar un BmpImage de otra instancia de RasterImage.
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
La imagen del raster es nula.
La altura debe ser positiva.
La paleta debe ser especificada para imágenes con 8 bits por pixel o menos.
BmpImage(RasterImage, ushort, BitmapCompression, doble, doble)
Comience trabajando con la clase Aspose.Imaging.FileFormats.Bmp.BmpImage sin problemas creando una nueva instanciautilizar un rasterImage junto con los parámetros especificados como bitsPerPixel y la compresión.Perfecto para los desarrolladores que buscan una manera sencilla de gestionar los objetos de BmpImage,garantizar la flexibilidad y la eficiencia de sus proyectos.
public BmpImage(RasterImage rasterImage, ushort bitsPerPixel, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
rasterImage
RasterImage
La imagen para iniciar los pixel y los datos de paleta con.
bitsPerPixel
ushort
Los bits por pixel.
compression
BitmapCompression
La composición para usar.
horizontalResolution
double
La resolución horizontal. Nota debido a la rotación la resolución resultante puede diferir ligeramente de la pasada.
verticalResolution
double
La resolución vertical. Nota debido a la rotación la resolución resultante puede diferir ligeramente de la pasada.
Examples
El ejemplo muestra cómo cargar un BmpImage de otra instancia de RasterImage con la profundidad y compresión de bit especificados.
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
La imagen del raster es nula.
La altura debe ser positiva.
La paleta debe ser especificada para imágenes con 8 bits por pixel o menos.
BmpImage(El int, int)
Comience utilizando la clase Aspose.Imaging.FileFormats.Bmp.BmpImage sin esfuerzo creando una nueva instanciacon parámetros especificados de ancho y altura. ideal para los desarrolladores que buscanuna forma conveniente de generar objetos BmpImage de dimensiones personalizadas, garantizandoflexibilidad y la facilidad de integración en sus proyectos.
public BmpImage(int width, int height)
Parameters
width
int
La imagen es amplia.
height
int
La altura de la imagen.
Examples
El ejemplo muestra cómo crear un BmpImage del tamaño especificado.
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");
}
El siguiente ejemplo muestra cómo paletizar una imagen BMP para reducir su tamaño de salida.
// 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
La altura debe ser positiva.
La paleta debe ser especificada para imágenes con 8 bits por pixel o menos.
BmpImage(int, int, ushort, IColorPalette)
Comience con el uso de la clase Aspose.Imaging.FileFormats.Bmp.BmpImage sin problemas iniciando una nueva instanciacon parámetros como ancho, altura, profundidad y paleta.desarrolladores que buscan una forma sencilla de crear objetos BmpImage condimensiones personalizadas y configuraciones de colores, garantizando la flexibilidad y la eficiencia en sus proyectos.
public BmpImage(int width, int height, ushort bitsPerPixel, IColorPalette palette)
Parameters
width
int
La imagen es amplia.
height
int
La altura de la imagen.
bitsPerPixel
ushort
Los bits por pixel.
palette
IColorPalette
La paleta de colores.
Examples
El ejemplo muestra cómo crear un BmpImage del tamaño especificado con la paleta especificada.
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
La altura debe ser positiva.
La paleta debe ser especificada para imágenes con 8 bits por pixel o menos.
BmpImage(int, int, ushort, IColorPalette, BitmapCompression, doble, doble)
Crea sin esfuerzo una nueva instancia de la clase Aspose.Imaging.FileFormats.Bmp.BmpImage con este constructor,especificando parámetros como ancho, altura, bitsPerPixel y paleta. Perfecto para desarrolladoresBuscando una manera conveniente de generar objetos BmpImage con dimensiones personalizadasy configuraciones de colores, garantizando la flexibilidad y la facilidad de la integración en sus proyectos.
public BmpImage(int width, int height, ushort bitsPerPixel, IColorPalette palette, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
width
int
La imagen es amplia.
height
int
La altura de la imagen.
bitsPerPixel
ushort
Los bits por pixel.
palette
IColorPalette
La paleta de colores.
compression
BitmapCompression
La composición para usar.
horizontalResolution
double
La resolución horizontal. Nota debido a la rotación la resolución resultante puede diferir ligeramente de la pasada.
verticalResolution
double
La resolución vertical. Nota debido a la rotación la resolución resultante puede diferir ligeramente de la pasada.
Examples
El ejemplo muestra cómo crear un BmpImage utilizando varias opciones.
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
La altura debe ser positiva.
La paleta debe ser especificada para imágenes con 8 bits por pixel o menos.
Properties
BitmapInfoHeader
Acceso rápido a los detalles esenciales de su imagen de bitmap con esta función sencilla.Perfecto para los desarrolladores que necesitan obtener información sobre los header para sus imágenes.
public BitmapInfoHeader BitmapInfoHeader { get; }
Valor de la propiedad
Examples
El siguiente ejemplo obtiene la información del título BMP y la imprime en la consola.
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
BitsPerPixel
Acceso al número de bits por pixel para la imagen con facilidad utilizando esta propiedad.Perfecto para los desarrolladores que buscan información rápida sobre la calidad y la profundidad de la imagen.
public override int BitsPerPixel { get; }
Valor de la propiedad
Examples
El siguiente ejemplo obtiene la información general sobre la imagen incluyendo el formato de píxeles, tamaño de la imagen, resolución, compresión, etc.
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
}
El siguiente ejemplo muestra cómo la compresión de bitmap afecta el tamaño de la imagen de salida.
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
Retirar el tipo de compresión utilizado para la imagen sin esfuerzo con esta propiedad.Perfecto para los desarrolladores que necesitan acceder rápidamente a la información sobre la compresión de imágenes.
public BitmapCompression Compression { get; }
Valor de la propiedad
Examples
El siguiente ejemplo obtiene la información general sobre la imagen incluyendo el formato de píxeles, tamaño de la imagen, resolución, compresión, etc.
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
}
El siguiente ejemplo muestra cómo la compresión de bitmap afecta el tamaño de la imagen de salida.
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
Obtenga fácilmente el valor del formato de archivo con esta propiedad amigable al usuario.Ideal para los desarrolladores que buscan acceso rápido a la información sobre el formato de archivo.
public override FileFormat FileFormat { get; }
Valor de la propiedad
Examples
El siguiente ejemplo muestra cómo extraer información sobre el formato de datos crudos y el canal alfa de una imagen BMP.
// 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
HasAlpha
Recibe un valor que indica si esta instancia tiene alfa.
public override bool HasAlpha { get; }
Valor de la propiedad
Height
Retire la altura de la imagen sin esfuerzo con esta propiedad. ideal para los desarrolladoresNecesitan acceso rápido a la información sobre las dimensiones de la imagen.
public override int Height { get; }
Valor de la propiedad
Examples
El siguiente ejemplo obtiene la información general sobre la imagen incluyendo el formato de píxeles, tamaño de la imagen, resolución, compresión, etc.
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
}
El siguiente ejemplo muestra cómo la compresión de bitmap afecta el tamaño de la imagen de salida.
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
Esta propiedad le permite obtener o configurar fácilmente la resolución horizontal,medida en píxeles por pulgón, del objeto Aspose.Imaging.RasterImage.Los desarrolladores necesitan un control preciso de la resolución de la imagen para sus aplicaciones.
public override double HorizontalResolution { get; set; }
Valor de la propiedad
Examples
El siguiente ejemplo muestra cómo definir la resolución horizontal/vertical de una imagen BMP.
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
}
El siguiente ejemplo obtiene la información general sobre la imagen incluyendo el formato de píxeles, tamaño de la imagen, resolución, compresión, etc.
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
Nota por defecto este valor es siempre 96 ya que las diferentes plataformas no pueden devolver la resolución de la pantalla. Puede considerar utilizar el método SetResolution para actualizar ambos valores de resolución en una sola llamada.
RawDataFormat
Obtenga fácilmente el formato de sus datos crudos con esta función amigable al usuario.Perfecto para los desarrolladores que buscan acceder rápidamente a información crucial sobre su formato de datos.
public override PixelDataFormat RawDataFormat { get; }
Valor de la propiedad
Examples
El siguiente ejemplo muestra cómo extraer información sobre el formato de datos crudos y el canal alfa de una imagen BMP.
// 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
El siguiente ejemplo obtiene la información general sobre la imagen incluyendo el formato de píxeles, tamaño de la imagen, resolución, compresión, etc.
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
Acceso rápido al tamaño de cada línea cruda en bytes con esta propiedad sencilla.Ideal para los desarrolladores que necesitan gestionar de manera eficiente los datos de imagen cruda.
public override int RawLineSize { get; }
Valor de la propiedad
Examples
El siguiente ejemplo obtiene la información general sobre la imagen incluyendo el formato de píxeles, tamaño de la imagen, resolución, compresión, etc.
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
}
El siguiente ejemplo muestra cómo la compresión de bitmap afecta el tamaño de la imagen de salida.
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
Recoger o configurar fácilmente la resolución vertical, medida en píxeles por pulgón,de este objeto Aspose.Imaging.RasterImage con esta propiedad. Perfecto para los desarrolladores que requierencontrol preciso de la resolución de la imagen en sus aplicaciones.
public override double VerticalResolution { get; set; }
Valor de la propiedad
Examples
El siguiente ejemplo muestra cómo definir la resolución horizontal/vertical de una imagen BMP.
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
}
El siguiente ejemplo obtiene la información general sobre la imagen incluyendo el formato de píxeles, tamaño de la imagen, resolución, compresión, etc.
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
Nota por defecto este valor es siempre 96 ya que las diferentes plataformas no pueden devolver la resolución de la pantalla. Puede considerar utilizar el método SetResolution para actualizar ambos valores de resolución en una sola llamada.
Width
Acceso a la anchura de la imagen fácilmente con esta propiedad. ideal para los desarrolladoresBuscar información rápida sobre las dimensiones de la imagen.
public override int Width { get; }
Valor de la propiedad
Examples
El siguiente ejemplo obtiene la información general sobre la imagen incluyendo el formato de píxeles, tamaño de la imagen, resolución, compresión, etc.
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
}
El siguiente ejemplo muestra cómo la compresión de bitmap afecta el tamaño de la imagen de salida.
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(Objeto[])
Retirar las opciones predefinidas sin esfuerzo con este método sencillo.Ideal para los desarrolladores que buscan un acceso rápido a las configuraciones o configuraciones de imagen predeterminadas.
public override ImageOptionsBase GetDefaultOptions(object[] args)
Parameters
args
object
[][]
Los argumentos.
Returns
Opciones defectuosas
OnCached()
Se llama cuando se cache los datos y todos los recursos relacionados pueden ser desallocados.
protected override void OnCached()
OnPaletteChanging(Coloración, Coloración, Coloración)
Se llama cuando la paleta cambia.
protected override void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)
Parameters
oldPalette
IColorPalette
La vieja paleta.
newPalette
IColorPalette
La nueva paleta.
SaveData(Stream)
ahorrar los datos.
protected override void SaveData(Stream stream)
Parameters
stream
Stream
El flujo para salvar los datos a.
SetResolution(doble, doble)
Ajustar la resolución de su Aspose.Imaging.RasterImage sin esfuerzo con esteperfecto para los desarrolladores que buscan control preciso sobreResolución de imágenes en sus aplicaciones.
public override void SetResolution(double dpiX, double dpiY)
Parameters
dpiX
double
La resolución horizontal, en puntos por pulgón, del Aspose.Imaging.RasterImage.
dpiY
double
La resolución vertical, en puntos por pulgón, del Aspose.Imaging.RasterImage.
Examples
El siguiente ejemplo muestra cómo definir la resolución horizontal/vertical de una imagen BMP.
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
}
El siguiente ejemplo obtiene la información general sobre la imagen incluyendo el formato de píxeles, tamaño de la imagen, resolución, compresión, etc.
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()
Convertir fácilmente su imagen de raster en un bitmap con este método sencillo.Perfecto para los desarrolladores que necesitan una transición sin sentido entre diferentes formatos de imagen.
public override Bitmap ToBitmap()
Returns
El bitmap
Examples
El siguiente ejemplo convierte una imagen BMP en un bitmap GDI.
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.
}
UpdateDimensions(El int, int)
Actualizar las dimensiones de la imagen.
protected override void UpdateDimensions(int newWidth, int newHeight)
Parameters
newWidth
int
La nueva imagen es amplia.
newHeight
int
El nuevo tamaño de la imagen.