Class ColorPaletteHelper

Class ColorPaletteHelper

Tên không gian: Aspose.Imaging Tổng hợp: Aspose.Imaging.dll (25.4.0)

Giúp lớp học cho việc thao túng pallet màu sắc.

public static class ColorPaletteHelper

Inheritance

object ColorPaletteHelper

Thành viên thừa kế

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

Methods

Create4Bit()

Tạo 4 bit màu palette.

public static IColorPalette Create4Bit()

Returns

IColorPalette

Bảng màu 4 bit

Create4BitGrayscale(Bool)

Tạo 4 bit grayscale palette.

public static IColorPalette Create4BitGrayscale(bool minIsWhite)

Parameters

minIsWhite bool

Nếu được thiết lập để “thực tế”, palette bắt đầu với màu trắng, nếu không nó bắt đầu với màu đen.

Returns

IColorPalette

4 bit grayscale pallet

Create8Bit()

Tạo ra bảng màu 8 bit.

public static IColorPalette Create8Bit()

Returns

IColorPalette

Màu sắc 8 bit

Create8BitGrayscale(Bool)

Tạo 8 bit grayscale palette.

public static IColorPalette Create8BitGrayscale(bool minIsWhite)

Parameters

minIsWhite bool

Nếu được thiết lập để “thực tế”, palette bắt đầu với màu trắng, nếu không nó bắt đầu với màu đen.

Returns

IColorPalette

8 bit grayscale pallet.

Examples

Ví dụ sau đây tạo ra một hình ảnh màu xám BMP và sau đó lưu nó vào một tệp.

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)

Nhận bảng màu xám của số bit cụ thể. giá trị bit được cho phép là 1, 2, 4, 8.

public static IColorPalette CreateGrayscale(int bits)

Parameters

bits int

Nhỏ đếm

Returns

IColorPalette

Đồ chơi Grayscale

Exceptions

ArgumentOutOfRangeException

bits'

CreateMonochrome()

Tạo một bảng màu monochrome chỉ chứa 2 màu.

public static IColorPalette CreateMonochrome()

Returns

IColorPalette

Màu sắc cho hình ảnh monochrome

GetCloseImagePalette(Đồ họa, int)

Nhận màu palette từ hình ảnh raster (palletizes hình ảnh) trong trường hợp hình ảnh không có một. trong trường hợp palette tồn tại nó sẽ được sử dụng thay vì thực hiện tính toán.

public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount)

Parameters

image RasterImage

Hình ảnh Raster

entriesCount int

Số lượng vào được mong muốn.

Returns

IColorPalette

Bảng màu bắt đầu với màu sắc phổ biến nhất từ image’ và chứa entriesCount’ entries.

Examples

Ví dụ sau đây tải lên một hình ảnh BMP và lưu lại nó trở lại BMPs bằng cách sử dụng các tùy chọn lưu khác nhau.

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

Ví dụ sau đây cho thấy làm thế nào để palletize một hình ảnh BMP để giảm kích thước output của nó.

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

Nhận màu palette từ hình ảnh raster (palletizes ảnh) trong trường hợp ảnh không có một. Palette sắp được tối ưu hóa cho chất lượng ảnh được chỉ định tốt hơn hoặc lấy “AS IS” khi PaleteMiningMethod.UseCurrentPalette được sử dụng.

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

Parameters

image RasterImage

Hình ảnh Raster

entriesCount int

Số lượng vào được mong muốn.

paletteMiningMethod PaletteMiningMethod

Phương pháp khai thác palette.

Returns

IColorPalette

Bảng màu bắt đầu với màu sắc phổ biến nhất từ image’ và chứa entriesCount’ entries.

Examples

Ví dụ sau đây cho thấy làm thế nào để nén một hình ảnh PNG, sử dụng màu indexed với tốt nhất phù hợp palette

// 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(Tính năng: Rectangle, int)

Nhận màu palette từ hình ảnh raster (palletizes hình ảnh) trong trường hợp hình ảnh không có một. trong trường hợp palette tồn tại nó sẽ được sử dụng thay vì thực hiện tính toán.

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

Parameters

image RasterImage

Hình ảnh Raster

destBounds Rectangle

Mục đích hình ảnh giới hạn.

entriesCount int

Số lượng vào được mong muốn.

Returns

IColorPalette

Bảng màu bắt đầu với màu sắc phổ biến nhất từ image’ và chứa entriesCount’ entries.

GetCloseImagePalette(RasterImage, Rectangle, int, bool)

Nhận màu palette từ hình ảnh raster (palletizes hình ảnh) trong trường hợp hình ảnh không có một. trong trường hợp palette tồn tại nó sẽ được sử dụng thay vì thực hiện tính toán.

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

Parameters

image RasterImage

Hình ảnh Raster

destBounds Rectangle

Mục đích hình ảnh giới hạn.

entriesCount int

Số lượng vào được mong muốn.

useImagePalette bool

Nếu thiết lập, nó sẽ sử dụng bảng hình ảnh của riêng mình nếu có sẵn

Returns

IColorPalette

Bảng màu bắt đầu với màu sắc phổ biến nhất từ image’ và chứa entriesCount’ entries.

GetCloseImagePalette(RasterImage, Rectangle, int, bool, Màu sắc)

Nhận màu palette từ hình ảnh raster (palletizes hình ảnh) trong trường hợp hình ảnh không có một. trong trường hợp palette tồn tại nó sẽ được sử dụng thay vì thực hiện tính toán.

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

Parameters

image RasterImage

Hình ảnh Raster

destBounds Rectangle

Mục đích hình ảnh giới hạn.

entriesCount int

Số lượng vào được mong muốn.

useImagePalette bool

Nếu thiết lập, nó sẽ sử dụng bảng hình ảnh của riêng mình nếu có sẵn

alphaBlendInColor Color

Màu sắc nên được sử dụng như một màu nền cho sự thay thế alpha bán minh bạch.

Returns

IColorPalette

Bảng màu bắt đầu với màu sắc phổ biến nhất từ image’ và chứa entriesCount’ entries.

GetCloseImagePalette(RasterImage, Rectangle, int, bool, Màu, Bool)

Nhận màu palette từ hình ảnh raster (palletizes hình ảnh) trong trường hợp hình ảnh không có một. trong trường hợp palette tồn tại nó sẽ được sử dụng thay vì thực hiện tính toán.

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

Parameters

image RasterImage

Hình ảnh Raster

destBounds Rectangle

Mục đích hình ảnh giới hạn.

entriesCount int

Số lượng vào được mong muốn.

useImagePalette bool

Nếu thiết lập, nó sẽ sử dụng bảng hình ảnh của riêng mình nếu có sẵn

alphaBlendInColor Color

Màu sắc nên được sử dụng như một màu nền cho sự thay thế alpha bán minh bạch.

keepTransparency bool

Nếu thiết lập, nó sẽ xem xét các bit kênh alpha của màu hình ảnh.

Returns

IColorPalette

Bảng màu bắt đầu với màu sắc phổ biến nhất từ image’ và chứa entriesCount’ entries.

GetCloseTransparentImagePalette(Đồ họa, int)

Nhận màu palette từ hình ảnh raster (palletizes hình ảnh) trong trường hợp hình ảnh không có một. trong trường hợp palette tồn tại nó sẽ được sử dụng thay vì thực hiện tính toán.

public static IColorPalette GetCloseTransparentImagePalette(RasterImage image, int entriesCount)

Parameters

image RasterImage

Hình ảnh Raster

entriesCount int

Số lượng vào được mong muốn.

Returns

IColorPalette

Bảng màu bắt đầu với màu sắc phổ biến nhất từ image’ và chứa entriesCount’ entries.

GetDownscalePalette(RasterImage)

Nhận bảng màu 256 bao gồm các bit trên các giá trị màu hình ảnh ban đầu.

public static ColorPalette GetDownscalePalette(RasterImage image)

Parameters

image RasterImage

hình ảnh .

Returns

ColorPalette

Các Aspose.Imaging.ColorPalette.

GetUniformColorPalette(RasterImage)

Đặt một bảng màu 256 màu.

public static ColorPalette GetUniformColorPalette(RasterImage image)

Parameters

image RasterImage

hình ảnh .

Returns

ColorPalette

Các Aspose.Imaging.ColorPalette.

HasTransparentColors(Đồ chơi ICOLOR)

Nó xác định liệu bảng được chỉ định có màu sắc minh bạch hay không.

public static bool HasTransparentColors(IColorPalette palette)

Parameters

palette IColorPalette

của palette.

Returns

bool

’truyền’ nếu bảng được chỉ định có màu sắc minh bạch; nếu không, ’lầm'.

Exceptions

ArgumentNullException

palette’ is null.

 Tiếng Việt