Class ColorPaletteHelper

Class ColorPaletteHelper

nazivni prostor: Aspose.Imaging Sastav: Aspose.Imaging.dll (25.4.0)

Pomoćni razred za manipulaciju paletama boja.

public static class ColorPaletteHelper

Inheritance

object ColorPaletteHelper

naslijeđeni članovi

object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Methods

Create4Bit()

Stvara 4 bitnu paletu boja.

public static IColorPalette Create4Bit()

Returns

IColorPalette

4 bitne palete boja.

Create4BitGrayscale(Bolić)

Stvara 4 bitnu paletu.

public static IColorPalette Create4BitGrayscale(bool minIsWhite)

Parameters

minIsWhite bool

ako je postavljena na “pravdu”, paleta počinje bijelom bojom, inače počinje crnom bojom.

Returns

IColorPalette

4 bitni grayscale paleta.

Create8Bit()

Stvara 8 bitnu paletu boja.

public static IColorPalette Create8Bit()

Returns

IColorPalette

8 bitne palete boja.

Create8BitGrayscale(Bolić)

Stvara 8 bitnu paletu.

public static IColorPalette Create8BitGrayscale(bool minIsWhite)

Parameters

minIsWhite bool

ako je postavljena na “pravdu”, paleta počinje bijelom bojom, inače počinje crnom bojom.

Returns

IColorPalette

8 bitni grayscale paleta.

Examples

Sljedeći primjer stvara paletirani grayscale BMP sliku, a zatim ga čuva u datoteku.

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

CreateGrayscale(int)

Dobiva paletu grayscale određenog broja bitova. dopuštene bitove vrijednosti su 1, 2, 4, 8.

public static IColorPalette CreateGrayscale(int bits)

Parameters

bits int

To je malo broja.

Returns

IColorPalette

Grajsko paleto.

Exceptions

ArgumentOutOfRangeException

bits'

CreateMonochrome()

Stvara monokromnu paletu boja koja sadrži samo dvije boje.

public static IColorPalette CreateMonochrome()

Returns

IColorPalette

Paleta boja za monokromne slike.

GetCloseImagePalette(Sljedeći Članak RasterImage, int)

Dobiva paletu boja iz raster slike (palletizira sliku) u slučaju da slika nema jednu.

public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount)

Parameters

image RasterImage

Istraživanje raster slike.

entriesCount int

Poželjna ulaznica se broji.

Returns

IColorPalette

Paleta boja koja počinje s najčešćim bojama iz image’ i sadrži entriesCount’ ulaznice.

Examples

Sljedeći primjer preuzima sliku BMP-a i spašava je nazad u BMM-u pomoću različitih opcija za štednju.

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

Sljedeći primjer pokazuje kako paletirati BMP sliku kako bi se smanjila njezina veličina izlaska.

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

GetCloseImagePalette(RasterImage, int, PaletteMiningMetoda)

Dobiva paletu boja iz raster slike (palletizira sliku) u slučaju da slika nema jednu. paleta će biti optimizirana za bolje indeksiranu kvalitetu slike ili uzeti “AS IS” kada se PaletteMiningMethod.UseCurrentPalette koristi.

public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount, PaletteMiningMethod paletteMiningMethod)

Parameters

image RasterImage

Istraživanje raster slike.

entriesCount int

Poželjna ulaznica se broji.

paletteMiningMethod PaletteMiningMethod

Metoda palete rudarstva.

Returns

IColorPalette

Paleta boja koja počinje s najčešćim bojama iz image’ i sadrži entriesCount’ ulaznice.

Examples

Sljedeći primjer pokazuje kako komprimirati PNG sliku, koristeći indeksiranu boju s najboljim paletom

// Loads png image        
                                                                                                                 string  sourceFilePath="OriginalRings.png";
                                                                                                                 string  outputFilePath="OriginalRingsOutput.png";
                                                                                                                 using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(sourceFilePath))
                                                                                                             {
                                                                                                                 image.Save(outputFilePath, new Aspose.Imaging.ImageOptions.PngOptions()
                                                                                                                 {
                                                                                                                      Progressive = true,
                                                                                                                          // Use indexed color type
                                                                                                                      ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.IndexedColor,
                                                                                                                          // Use maximal compression
                                                                                                                      CompressionLevel = 9,
                                                                                                                   // 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.
                                                                                                                      Palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette((Aspose.Imaging.RasterImage)image, 256, Aspose.Imaging.PaletteMiningMethod.Histogram)
                                                                                                                 });
                                                                                                             }
                                                                                                                 // The output file size should be significantly reduced

GetCloseImagePalette(RasterImage, Rectangle, int)

Dobiva paletu boja iz raster slike (palletizira sliku) u slučaju da slika nema jednu.

public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount)

Parameters

image RasterImage

Istraživanje raster slike.

destBounds Rectangle

Ciljna slika ograničava.

entriesCount int

Poželjna ulaznica se broji.

Returns

IColorPalette

Paleta boja koja počinje s najčešćim bojama iz image’ i sadrži entriesCount’ ulaznice.

GetCloseImagePalette(RasterImage, Rectangle, int, bool)

Dobiva paletu boja iz raster slike (palletizira sliku) u slučaju da slika nema jednu.

public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, bool useImagePalette)

Parameters

image RasterImage

Istraživanje raster slike.

destBounds Rectangle

Ciljna slika ograničava.

entriesCount int

Poželjna ulaznica se broji.

useImagePalette bool

Ako je postavljen, koristi vlastitu paletu slika ako je dostupna

Returns

IColorPalette

Paleta boja koja počinje s najčešćim bojama iz image’ i sadrži entriesCount’ ulaznice.

GetCloseImagePalette(RasterImage, Rectangle, int, bool, Boja)

Dobiva paletu boja iz raster slike (palletizira sliku) u slučaju da slika nema jednu.

public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, bool useImagePalette, Color alphaBlendInColor)

Parameters

image RasterImage

Istraživanje raster slike.

destBounds Rectangle

Ciljna slika ograničava.

entriesCount int

Poželjna ulaznica se broji.

useImagePalette bool

Ako je postavljen, koristi vlastitu paletu slika ako je dostupna

alphaBlendInColor Color

Boja koja bi trebala biti upotrijebljena kao boja pozadine za semi-transparentnu alfa zamjenu.

Returns

IColorPalette

Paleta boja koja počinje s najčešćim bojama iz image’ i sadrži entriesCount’ ulaznice.

GetCloseImagePalette(RasterImage, Rectangle, int, bool, Bool)

Dobiva paletu boja iz raster slike (palletizira sliku) u slučaju da slika nema jednu.

public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, bool useImagePalette, Color alphaBlendInColor, bool keepTransparency)

Parameters

image RasterImage

Istraživanje raster slike.

destBounds Rectangle

Ciljna slika ograničava.

entriesCount int

Poželjna ulaznica se broji.

useImagePalette bool

Ako je postavljen, koristi vlastitu paletu slika ako je dostupna

alphaBlendInColor Color

Boja koja bi trebala biti upotrijebljena kao boja pozadine za semi-transparentnu alfa zamjenu.

keepTransparency bool

Ako je postavljen, uzeti će u obzir alfa kanala bitova boja slike.

Returns

IColorPalette

Paleta boja koja počinje s najčešćim bojama iz image’ i sadrži entriesCount’ ulaznice.

GetCloseTransparentImagePalette(Sljedeći Članak RasterImage, int)

Dobiva paletu boja iz raster slike (palletizira sliku) u slučaju da slika nema jednu.

public static IColorPalette GetCloseTransparentImagePalette(RasterImage image, int entriesCount)

Parameters

image RasterImage

Istraživanje raster slike.

entriesCount int

Poželjna ulaznica se broji.

Returns

IColorPalette

Paleta boja koja počinje s najčešćim bojama iz image’ i sadrži entriesCount’ ulaznice.

GetDownscalePalette(RasterImage)

Dobijte 256 palete boja, koje se sastoje od gornjih bitova početnih vrijednosti boja slike.

public static ColorPalette GetDownscalePalette(RasterImage image)

Parameters

image RasterImage

Na sliku je.

Returns

ColorPalette

Sljedeći Članak Aspose.Imaging.ColorPalette

GetUniformColorPalette(RasterImage)

Uzmite jedinstvenu paletu od 256 boja.

public static ColorPalette GetUniformColorPalette(RasterImage image)

Parameters

image RasterImage

Na sliku je.

Returns

ColorPalette

Sljedeći Članak Aspose.Imaging.ColorPalette

HasTransparentColors(ICOLORPALETE)

Određuje ima li određena paleta transparentne boje.

public static bool HasTransparentColors(IColorPalette palette)

Parameters

palette IColorPalette

To je paleta.

Returns

bool

‘Pravda’ ako navedena paleta ima transparentne boje; inače, ’lažna’.

Exceptions

ArgumentNullException

palette’ is null.

 Hrvatski