Class BmpOptions

Class BmpOptions

Il nome: Aspose.Imaging.ImageOptions Assemblea: Aspose.Imaging.dll (25.4.0)

L’API per le opzioni di creazione del formato BMP e DIB raster immagine fornisce agli sviluppatoricon un set di strumenti versatile per generare Bitmap (BMP) e Dispositivo personalizzatoImmagini Bitmap indipendenti (DIB). con questa API, è possibile definire esattamenteCaratteristiche dell’immagine come bit per pixel, livello di compressione e compresionetipo, adattando la produzione per soddisfare i requisiti specifici.API consente agli sviluppatori di creare immagini raster di alta qualità e personalizzateFacilità e flessibilità per diverse applicazioni.

public class BmpOptions : ImageOptionsBase, IDisposable, IHasXmpData, IHasMetadata, ICloneable

Inheritance

object DisposableObject ImageOptionsBase BmpOptions

Implements

IDisposable , IHasXmpData , IHasMetadata , ICloneable

I membri ereditari

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

Questo esempio crea un nuovo file di Immagine in qualche posizione del disco come specificato dalla proprietà Source dell’esempio BmpOptions. Diverse proprietà per l’installazione Bmoptions sono impostate prima di creare la immagine reale. In particolare, la proprietà della Fonte, che si riferisce all’attuale posizione disco in questo caso.

//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();
                                                                                                                                                                                                                                                                                                             }

Questo esempio dimostra l’uso di diverse classi da SaveOptions Namespace per scopi di esportazione. Un’immagine del tipo Gif viene caricata in un esempio di Immagine e poi esportata a diversi formati.

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));
                                                                                                                                                                                                                    }

L’esempio seguente mostra come convertire un’immagine vector multipagine in formato BMP in generale senza fare riferimento a un particolare tipo di immagine.

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

Inizia una nuova instanza della classe Aspose.Imaging.ImageOptions.BmpOption.

public BmpOptions()

Examples

L’esempio seguente carica un’immagine BMP e lo salva indietro al BMM utilizzando varie opzioni di risparmio.

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);
                                                                                                       }

L’esempio seguente crea un’immagine di grayscale BMP palettizzata e lo salva in un file.

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)

Inizia una nuova instanza della classe Aspose.Imaging.ImageOptions.BmpOption.

public BmpOptions(BmpOptions bmpOptions)

Parameters

bmpOptions BmpOptions

Le opzioni di BMP.

Properties

BitsPerPixel

Riceve o impone i bit di immagine per pixel.

public int BitsPerPixel { get; set; }

Valore di proprietà

int

Examples

L’esempio seguente carica un’immagine BMP e lo salva indietro al BMM utilizzando varie opzioni di risparmio.

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);
                                                                                                       }

L’esempio seguente crea un’immagine di grayscale BMP palettizzata e lo salva in un file.

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();
                                                                                                      }

L’esempio seguente mostra come palletizzare un’immagine BMP per ridurre la sua dimensione di uscita.

// 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

Il tipo di compressione predefinito è Aspose.Imaging.FileFormats.Bmp. BitmapCompression.bitfields, che consente di salvare un Wl17.Diploma.com con trasparenza.

public BitmapCompression Compression { get; set; }

Valore di proprietà

BitmapCompression

Examples

Immagine BMP che è stata precedentemente compressa utilizzando l’algoritmo di compressione DXT1.

using (var image = Image.Load("CompressedTiger.bmp"))
                                                                                                 {
                                                                                                     image.Save("DecompressedTiger.bmp", new BmpOptions());
                                                                                                 }

Comprimere immagine BMP utilizzando l’algoritmo di compressione DXT1.

using (var image = Image.Load("Tiger.bmp"))
                                                               {
                                                                   image.Save("CompressedTiger.bmp", new BmpOptions { Compression = BitmapCompression.Dxt1 });
                                                               }

L’esempio mostra come esportare un BmpImage con il tipo di compressione 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 });
                                                                                    }

L’esempio mostra come esportare un BmpImage da un file Png mentre mantiene il canale alfa, risparmiando il file BMP con trasparenza.

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 });
                                                                                                                                         }

L’esempio seguente carica un’immagine BMP e lo salva indietro al BMM utilizzando varie opzioni di risparmio.

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);
                                                                                                       }

L’esempio seguente crea un’immagine di grayscale BMP palettizzata e lo salva in un file.

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();
                                                                                                      }
 Italiano