Class BmpOptions
Именује се: Aspose.Imaging.ImageOptions Асамблеја: Aspose.Imaging.dll (25.4.0)
АПИ за БМП и ДИБ опције за креирање формата слике пружају програмеримаса свеобухватним алатним сетом за генерисање прилагођених Битмапа (БМП) и уређајаНезависни Битмап (ДИБ) слике. са овим АПИ-ом, можете тачно дефинисатиКарактеристике слике као што су битови по пикселу, ниво компресије и компромисврста, прилагођавање производње да задовољи специфичне захтеве. ово карактеристично богатоАПИ омогућава програмерима да креирају висококвалитетне, прилагођене растер сликеЈедноставност и флексибилност за различите апликације.
public class BmpOptions : ImageOptionsBase, IDisposable, IHasXmpData, IHasMetadata, ICloneable
Inheritance
object ← DisposableObject ← ImageOptionsBase ← BmpOptions
Implements
IDisposable , IHasXmpData , IHasMetadata , ICloneable
Наслеђени чланови
ImageOptionsBase.Clone() , ImageOptionsBase.ReleaseManagedResources() , ImageOptionsBase.KeepMetadata , ImageOptionsBase.XmpData , ImageOptionsBase.Source , ImageOptionsBase.Palette , ImageOptionsBase.ResolutionSettings , ImageOptionsBase.VectorRasterizationOptions , ImageOptionsBase.BufferSizeHint , ImageOptionsBase.MultiPageOptions , ImageOptionsBase.FullFrame , ImageOptionsBase.ProgressEventHandler , DisposableObject.Dispose() , DisposableObject.ReleaseManagedResources() , DisposableObject.ReleaseUnmanagedResources() , DisposableObject.VerifyNotDisposed() , DisposableObject.Disposed , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
Овај пример креира нови Слика датотеку на неком локацији диска, као што је наведено изворном својством инстанције Бмпоптионс. Неколико својстава за Инстанцију БМп опције се поставља пре стварања стварног слике.
//Create an instance of BmpOptions and set its various properties
Aspose.Imaging.ImageOptions.BmpOptions bmpOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
bmpOptions.BitsPerPixel = 24;
//Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
//Second Boolean parameter determines if the file to be created IsTemporal or not
bmpOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"C:\temp\output.bmp", false);
//Create an instance of Image and initialize it with instance of BmpOptions by calling Create method
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(bmpOptions, 500, 500))
{
//do some image processing
// save all changes
image.Save();
}
Овај пример показује употребу различитих класа из SaveOptions Namespace за извозне сврхе. слика типа Gif се наплаћује у примјену слике, а затим се извози у неколико формата.
string dir = "c:\\temp\\";
//Load an existing image (of type Gif) in an instance of Image class
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
{
//Export to BMP file format using the default options
image.Save(dir + "output.bmp", new Aspose.Imaging.ImageOptions.BmpOptions());
//Export to JPEG file format using the default options
image.Save(dir + "output.jpg", new Aspose.Imaging.ImageOptions.JpegOptions());
//Export to PNG file format using the default options
image.Save(dir + "output.png", new Aspose.Imaging.ImageOptions.PngOptions());
//Export to TIFF file format using the default options
image.Save(dir + "output.tif", new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default));
}
Следећи пример показује како конвертовати вишестраничну векторску слику у БМП формат уопште без референције на одређени тип слике.
string dir = "C:\\aspose.imaging\\net\\misc\\ImagingReleaseQATester\\Tests\\testdata\\2548";
string inputFilePath = System.IO.Path.Combine(dir, "Multipage.cdr");
string outputFilePath = System.IO.Path.Combine(dir, "Multipage.cdr.bmp");
Aspose.Imaging.ImageOptionsBase exportOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(inputFilePath))
{
exportOptions.MultiPageOptions = null;
// Export only first two pages. In fact, only one page will be rasterized because BMP is not a multi-page format.
Aspose.Imaging.IMultipageImage multipageImage = image as Aspose.Imaging.IMultipageImage;
if (multipageImage != null && (multipageImage.Pages != null && multipageImage.PageCount > 2))
{
exportOptions.MultiPageOptions = new Aspose.Imaging.ImageOptions.MultiPageOptions(new Aspose.Imaging.IntRange(0, 2));
}
if (image is Aspose.Imaging.VectorImage)
{
exportOptions.VectorRasterizationOptions = (Aspose.Imaging.ImageOptions.VectorRasterizationOptions)image.GetDefaultOptions(new object[] { Aspose.Imaging.Color.White, image.Width, image.Height });
exportOptions.VectorRasterizationOptions.TextRenderingHint = Aspose.Imaging.TextRenderingHint.SingleBitPerPixel;
exportOptions.VectorRasterizationOptions.SmoothingMode = Aspose.Imaging.SmoothingMode.None;
}
image.Save(outputFilePath, exportOptions);
}
Constructors
BmpOptions()
Иницијалише нову инстанцију класе Aspose.Imaging.ImageOptions.BmpOption.
public BmpOptions()
Examples
Следећи пример преузима БМП слику и спасава га назад на БМП користећи различите опције за сачување.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Create BmpOptions
Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
// Use 8 bits per pixel to reduce the size of the output image.
saveOptions.BitsPerPixel = 8;
// Set the closest 8-bit color palette which covers the maximal number of image pixels, so that a palettized image
// is almost visually indistinguishable from a non-palletized one.
saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette(rasterImage, 256);
// Save without compression.
// You can also use RLE-8 compression to reduce the size of the output image.
saveOptions.Compression = Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb;
// Set the horizontal and vertical resolution to 96 dpi.
saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
image.Save(dir + "sample.bmpoptions.bmp", saveOptions);
}
Следећи пример ствара палетизовану слику БМП и затим га чува у датотеку.
string dir = "c:\\temp\\";
Aspose.Imaging.ImageOptions.BmpOptions createOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
// Save to a file
createOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(dir + "output.palette8bit.bmp", false);
// Use 8 bits per pixel to reduce the size of the output image.
createOptions.BitsPerPixel = 8;
// Set the standard 8-bit grayscale color palette which covers all grayscale colors.
// If the processed image contains only grayscale colors, then its palettized version
// is visually indistinguishable from a non-palletized one.
createOptions.Palette = Aspose.Imaging.ColorPaletteHelper.Create8BitGrayscale(false);
// Save without compression.
// You can also use RLE-8 compression to reduce the size of the output image.
createOptions.Compression = Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb;
// Set the horizontal and vertical resolution to 96 dpi.
createOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
// Create a BMP image of 100 x 100 px and save it to a file.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(createOptions, 100, 100))
{
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
new Aspose.Imaging.Point(0, 0),
new Aspose.Imaging.Point(image.Width, image.Height),
Aspose.Imaging.Color.Black,
Aspose.Imaging.Color.White);
// Fill the image with a grayscale gradient
graphics.FillRectangle(gradientBrush, image.Bounds);
image.Save();
}
BmpOptions(BmpOptions)
Иницијалише нову инстанцију класе Aspose.Imaging.ImageOptions.BmpOption.
public BmpOptions(BmpOptions bmpOptions)
Parameters
bmpOptions
BmpOptions
Опције за БМП.
Properties
BitsPerPixel
Добијете или постављате бите слике по пикселу.
public int BitsPerPixel { get; set; }
Вредност имовине
Examples
Следећи пример преузима БМП слику и спасава га назад на БМП користећи различите опције за сачување.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Create BmpOptions
Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
// Use 8 bits per pixel to reduce the size of the output image.
saveOptions.BitsPerPixel = 8;
// Set the closest 8-bit color palette which covers the maximal number of image pixels, so that a palettized image
// is almost visually indistinguishable from a non-palletized one.
saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette(rasterImage, 256);
// Save without compression.
// You can also use RLE-8 compression to reduce the size of the output image.
saveOptions.Compression = Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb;
// Set the horizontal and vertical resolution to 96 dpi.
saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
image.Save(dir + "sample.bmpoptions.bmp", saveOptions);
}
Следећи пример ствара палетизовану слику БМП и затим га чува у датотеку.
string dir = "c:\\temp\\";
Aspose.Imaging.ImageOptions.BmpOptions createOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
// Save to a file
createOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(dir + "output.palette8bit.bmp", false);
// Use 8 bits per pixel to reduce the size of the output image.
createOptions.BitsPerPixel = 8;
// Set the standard 8-bit grayscale color palette which covers all grayscale colors.
// If the processed image contains only grayscale colors, then its palettized version
// is visually indistinguishable from a non-palletized one.
createOptions.Palette = Aspose.Imaging.ColorPaletteHelper.Create8BitGrayscale(false);
// Save without compression.
// You can also use RLE-8 compression to reduce the size of the output image.
createOptions.Compression = Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb;
// Set the horizontal and vertical resolution to 96 dpi.
createOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
// Create a BMP image of 100 x 100 px and save it to a file.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(createOptions, 100, 100))
{
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
new Aspose.Imaging.Point(0, 0),
new Aspose.Imaging.Point(image.Width, image.Height),
Aspose.Imaging.Color.Black,
Aspose.Imaging.Color.White);
// Fill the image with a grayscale gradient
graphics.FillRectangle(gradientBrush, image.Bounds);
image.Save();
}
Следећи пример показује како палетизовати БМП слику како би се смањила његова величина излаза.
// 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.
Compression
Стандардни тип компресије је ВЛ17.ФилеФорматис.Бмп.БитмапКомпресија.БИтфилдс, што омогућава да се сачувате на _WL17.FileFormats.Bmp.Снимке са транспаренцијом.
public BitmapCompression Compression { get; set; }
Вредност имовине
Examples
Декомпресирајте БМП слику која је раније компресирана користећи алгоритам компризије ДКСТ1.
using (var image = Image.Load("CompressedTiger.bmp"))
{
image.Save("DecompressedTiger.bmp", new BmpOptions());
}
Компресирајте БМП слику користећи алгоритам компресије ДКСТ1.
using (var image = Image.Load("Tiger.bmp"))
{
image.Save("CompressedTiger.bmp", new BmpOptions { Compression = BitmapCompression.Dxt1 });
}
Пример показује како извозити БмпИмаге са типом РГБ компресије.
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 });
}
Пример показује како извозити БмпИмаге из Пнг датотеке док држи алфа канал, сачувајући БМП-файл са транспаренцијом.
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 });
}
Следећи пример преузима БМП слику и спасава га назад на БМП користећи различите опције за сачување.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Create BmpOptions
Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
// Use 8 bits per pixel to reduce the size of the output image.
saveOptions.BitsPerPixel = 8;
// Set the closest 8-bit color palette which covers the maximal number of image pixels, so that a palettized image
// is almost visually indistinguishable from a non-palletized one.
saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette(rasterImage, 256);
// Save without compression.
// You can also use RLE-8 compression to reduce the size of the output image.
saveOptions.Compression = Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb;
// Set the horizontal and vertical resolution to 96 dpi.
saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
image.Save(dir + "sample.bmpoptions.bmp", saveOptions);
}
Следећи пример ствара палетизовану слику БМП и затим га чува у датотеку.
string dir = "c:\\temp\\";
Aspose.Imaging.ImageOptions.BmpOptions createOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
// Save to a file
createOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(dir + "output.palette8bit.bmp", false);
// Use 8 bits per pixel to reduce the size of the output image.
createOptions.BitsPerPixel = 8;
// Set the standard 8-bit grayscale color palette which covers all grayscale colors.
// If the processed image contains only grayscale colors, then its palettized version
// is visually indistinguishable from a non-palletized one.
createOptions.Palette = Aspose.Imaging.ColorPaletteHelper.Create8BitGrayscale(false);
// Save without compression.
// You can also use RLE-8 compression to reduce the size of the output image.
createOptions.Compression = Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb;
// Set the horizontal and vertical resolution to 96 dpi.
createOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
// Create a BMP image of 100 x 100 px and save it to a file.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(createOptions, 100, 100))
{
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
new Aspose.Imaging.Point(0, 0),
new Aspose.Imaging.Point(image.Width, image.Height),
Aspose.Imaging.Color.Black,
Aspose.Imaging.Color.White);
// Fill the image with a grayscale gradient
graphics.FillRectangle(gradientBrush, image.Bounds);
image.Save();
}