Class ColorPaletteHelper

Class ColorPaletteHelper

A név: Aspose.Imaging Összefoglaló: Aspose.Imaging.dll (25.4.0)

Segítő osztály a színes paletták manipulációja.

public static class ColorPaletteHelper

Inheritance

object ColorPaletteHelper

Örökletes tagok

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

Methods

Create4Bit()

Hozza létre a 4 bites színpalettát.

public static IColorPalette Create4Bit()

Returns

IColorPalette

A 4 bites színes palettát.

Create4BitGrayscale(Bóli)

A 4 bites grayscale palettát hozza létre.

public static IColorPalette Create4BitGrayscale(bool minIsWhite)

Parameters

minIsWhite bool

Ha a “igaz” a palettát fehér színvel kezdődik, különben fekete színvel kezdődik.

Returns

IColorPalette

A 4 bites grayscale palettát.

Create8Bit()

Hozza létre a 8 bites színpalettát.

public static IColorPalette Create8Bit()

Returns

IColorPalette

A 8 bites színes palettát.

Create8BitGrayscale(Bóli)

Hozza létre a 8 bites szürke palettát.

public static IColorPalette Create8BitGrayscale(bool minIsWhite)

Parameters

minIsWhite bool

Ha a “igaz” a palettát fehér színvel kezdődik, különben fekete színvel kezdődik.

Returns

IColorPalette

A 8 bites grayscale palettája.

Examples

Az alábbi példa létrehoz egy palettált grayscale BMP képet, majd mentse a fájl.

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)

A megengedett bitértékek 1, 2, 4, 8 értékűek.

public static IColorPalette CreateGrayscale(int bits)

Parameters

bits int

A kis számítás.

Returns

IColorPalette

A Grayscale palettája.

Exceptions

ArgumentOutOfRangeException

bits'

CreateMonochrome()

Egy monochróm színpalettát hoz létre, amely csak 2 színt tartalmaz.

public static IColorPalette CreateMonochrome()

Returns

IColorPalette

Színpaletták monochróm képekhez.

GetCloseImagePalette(Rákóczi, int)

Színpalettát kap a raster képből (palletizes kép) abban az esetben, ha a képnek nincs.

public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount)

Parameters

image RasterImage

A raster kép.

entriesCount int

A kívánt bejegyzések számolása.

Returns

IColorPalette

A színpaletta, amely a image’ leggyakoribb színekkel kezdődik, és tartalmazza a entriesCount’ bejegyzéseit.

Examples

A következő példa feltölti a BMP képet, és a különböző mentési opciók segítségével mentheti vissza a BMP-t.

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

Az alábbi példa azt mutatja, hogyan kell palettálni egy BMP képet, hogy csökkentsék a kimeneti méretét.

// 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, PaletteMiningMethod)

Színpalettát kap a raster képből (palletizes kép) abban az esetben, ha a képnek nincs egy. A palette a jobb indexelt képminőség érdekében optimalizálásra kerül, vagy a PaletteMiningMethod.UseCurrentPalette használatakor “AS IS” címet kapja.

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

Parameters

image RasterImage

A raster kép.

entriesCount int

A kívánt bejegyzések számolása.

paletteMiningMethod PaletteMiningMethod

A palettás bányászat módszere.

Returns

IColorPalette

A színpaletta, amely a image’ leggyakoribb színekkel kezdődik, és tartalmazza a entriesCount’ bejegyzéseit.

Examples

A következő példa azt mutatja, hogyan kell tömöríteni egy PNG képet, indexelt színt használva a legjobb illeszkedő palettával

// 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(Részletesebben Rectangle, int)

Színpalettát kap a raster képből (palletizes kép) abban az esetben, ha a képnek nincs.

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

Parameters

image RasterImage

A raster kép.

destBounds Rectangle

A rendeltetési kép korlátozódik.

entriesCount int

A kívánt bejegyzések számolása.

Returns

IColorPalette

A színpaletta, amely a image’ leggyakoribb színekkel kezdődik, és tartalmazza a entriesCount’ bejegyzéseit.

GetCloseImagePalette(RasterImage, Rectangle, int, bool)

Színpalettát kap a raster képből (palletizes kép) abban az esetben, ha a képnek nincs.

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

Parameters

image RasterImage

A raster kép.

destBounds Rectangle

A rendeltetési kép korlátozódik.

entriesCount int

A kívánt bejegyzések számolása.

useImagePalette bool

Ha be van állítva, akkor saját képpalettáját használja, ha rendelkezésre áll

Returns

IColorPalette

A színpaletta, amely a image’ leggyakoribb színekkel kezdődik, és tartalmazza a entriesCount’ bejegyzéseit.

GetCloseImagePalette(RasterImage, Rectangle, int, bool, Szín)

Színpalettát kap a raster képből (palletizes kép) abban az esetben, ha a képnek nincs.

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

Parameters

image RasterImage

A raster kép.

destBounds Rectangle

A rendeltetési kép korlátozódik.

entriesCount int

A kívánt bejegyzések számolása.

useImagePalette bool

Ha be van állítva, akkor saját képpalettáját használja, ha rendelkezésre áll

alphaBlendInColor Color

A szín, amelyet háttérszínként kell használni a fél átlátszó alfa helyettesítéshez.

Returns

IColorPalette

A színpaletta, amely a image’ leggyakoribb színekkel kezdődik, és tartalmazza a entriesCount’ bejegyzéseit.

GetCloseImagePalette(RasterImage, Rectangle, int, bool, Szín, Bool)

Színpalettát kap a raster képből (palletizes kép) abban az esetben, ha a képnek nincs.

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

Parameters

image RasterImage

A raster kép.

destBounds Rectangle

A rendeltetési kép korlátozódik.

entriesCount int

A kívánt bejegyzések számolása.

useImagePalette bool

Ha be van állítva, akkor saját képpalettáját használja, ha rendelkezésre áll

alphaBlendInColor Color

A szín, amelyet háttérszínként kell használni a fél átlátszó alfa helyettesítéshez.

keepTransparency bool

Ha be van állítva, akkor az alfa csatorna bitjeit a kép színeinek figyelembe veszik.

Returns

IColorPalette

A színpaletta, amely a image’ leggyakoribb színekkel kezdődik, és tartalmazza a entriesCount’ bejegyzéseit.

GetCloseTransparentImagePalette(Rákóczi, int)

Színpalettát kap a raster képből (palletizes kép) abban az esetben, ha a képnek nincs.

public static IColorPalette GetCloseTransparentImagePalette(RasterImage image, int entriesCount)

Parameters

image RasterImage

A raster kép.

entriesCount int

A kívánt bejegyzések számolása.

Returns

IColorPalette

A színpaletta, amely a image’ leggyakoribb színekkel kezdődik, és tartalmazza a entriesCount’ bejegyzéseit.

GetDownscalePalette(RasterImage)

Szerezzen 256 színpalettát, amely az eredeti képszínértékek felső bitjeiből áll.

public static ColorPalette GetDownscalePalette(RasterImage image)

Parameters

image RasterImage

A képet.

Returns

ColorPalette

Az WL17_.ColorPalette

GetUniformColorPalette(RasterImage)

Szerezzen egyenletes 256 színes palettát.

public static ColorPalette GetUniformColorPalette(RasterImage image)

Parameters

image RasterImage

A képet.

Returns

ColorPalette

Az WL17_.ColorPalette

HasTransparentColors(Színes paletták)

Határozza meg, hogy a kijelölt paletta átlátszó színekkel rendelkezik-e.

public static bool HasTransparentColors(IColorPalette palette)

Parameters

palette IColorPalette

Ez a paletta.

Returns

bool

„valódi”, ha a kijelölt paletta átlátszó színekkel rendelkezik; máskülönben „valódi”.

Exceptions

ArgumentNullException

palette’ is null.

 Magyar