Class ColorPaletteHelper

Class ColorPaletteHelper

ชื่อพื้นที่: Aspose.Imaging การประกอบ: Aspose.Imaging.dll (25.4.0)

เคล็ดลับความช่วยเหลือสําหรับการจัดการสี

public static class ColorPaletteHelper

Inheritance

object ColorPaletteHelper

อนุญาโตตุลาการ

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

Methods

Create4Bit()

สร้างแพลตฟอร์มสี 4 bit

public static IColorPalette Create4Bit()

Returns

IColorPalette

แผ่นสี 4 บิต

Create4BitGrayscale(บอล)

สร้างแพลตฟอร์มสีเทา 4 บิต

public static IColorPalette Create4BitGrayscale(bool minIsWhite)

Parameters

minIsWhite bool

หากกําหนดไว้เป็น “จริง” แพลิเคชันเริ่มต้นด้วยสีขาวหรือเริ่มต้นด้วยสีดํา

Returns

IColorPalette

แผ่นสีเทา 4 บิต

Create8Bit()

สร้างแพลตฟอร์มสี 8 bit

public static IColorPalette Create8Bit()

Returns

IColorPalette

แผ่นสี 8 บิต

Create8BitGrayscale(บอล)

สร้างแพลตฟอร์มสีเทา 8 บิต

public static IColorPalette Create8BitGrayscale(bool minIsWhite)

Parameters

minIsWhite bool

หากกําหนดไว้เป็น “จริง” แพลิเคชันเริ่มต้นด้วยสีขาวหรือเริ่มต้นด้วยสีดํา

Returns

IColorPalette

แผ่นสีเทา 8 บิต

Examples

ตัวอย่างต่อไปนี้จะสร้างภาพ BMP Grayscale แบบพลาสติกแล้วบันทึกไว้ในไฟล์

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)

รับค่าบิตที่อนุญาตเป็น 1, 2, 4, 8

public static IColorPalette CreateGrayscale(int bits)

Parameters

bits int

หมายเลขขนาดเล็ก

Returns

IColorPalette

แผ่น Grayscale

Exceptions

ArgumentOutOfRangeException

bits'

CreateMonochrome()

สร้างแพลตฟอร์มสี monochrome ที่มี 2 สีเท่านั้น

public static IColorPalette CreateMonochrome()

Returns

IColorPalette

แผ่นสีสําหรับภาพ monochrome

GetCloseImagePalette(สื่อลามก, int)

ได้รับสีแพลตฟอร์มจากภาพเรสเตอร์ (ภาพแพลตฟอร์ม) ในกรณีที่ภาพไม่ได้มีหนึ่ง ในกรณีที่แพลตฟอร์มมีมันจะถูกใช้แทนที่จะดําเนินการคํานวณ

public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount)

Parameters

image RasterImage

รูปภาพสกรู

entriesCount int

จํานวนรายการที่ต้องการ

Returns

IColorPalette

แผนสีที่เริ่มต้นด้วยสีที่พบมากที่สุดจาก image’ และมี entriesCount’ entries

Examples

ตัวอย่างต่อไปนี้โหลดภาพ BMP และบันทึกมันกลับไปยัง BMP โดยใช้ตัวเลือกการบันทึกต่างๆ

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

ตัวอย่างต่อไปนี้แสดงให้เห็นว่าวิธีการ palletize ภาพ BMP เพื่อลดขนาดการผลิต

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

ได้รับสีแพลตฟอร์มจากภาพเรสเตอร์ (palletizes ภาพ) ในกรณีที่ภาพไม่ได้มีหนึ่ง แพลตฟอร์มจะได้รับการปรับปรุงเพื่อคุณภาพภาพที่ indexed ดีขึ้นหรือใช้ “AS IS” เมื่อ PaletteMiningMethod.UseCurrentPalette ใช้

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

Parameters

image RasterImage

รูปภาพสกรู

entriesCount int

จํานวนรายการที่ต้องการ

paletteMiningMethod PaletteMiningMethod

วิธีการทําเหมืองแร่

Returns

IColorPalette

แผนสีที่เริ่มต้นด้วยสีที่พบมากที่สุดจาก image’ และมี entriesCount’ entries

Examples

ตัวอย่างต่อไปนี้แสดงให้เห็นวิธีการบีบอัดภาพ PNG โดยใช้สีที่ระบุด้วยแพลตฟอร์มที่ดีที่สุด

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

ได้รับสีแพลตฟอร์มจากภาพเรสเตอร์ (ภาพแพลตฟอร์ม) ในกรณีที่ภาพไม่ได้มีหนึ่ง ในกรณีที่แพลตฟอร์มมีมันจะถูกใช้แทนที่จะดําเนินการคํานวณ

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

Parameters

image RasterImage

รูปภาพสกรู

destBounds Rectangle

จุดหมายปลายทางรูปภาพ จํากัด

entriesCount int

จํานวนรายการที่ต้องการ

Returns

IColorPalette

แผนสีที่เริ่มต้นด้วยสีที่พบมากที่สุดจาก image’ และมี entriesCount’ entries

GetCloseImagePalette(RasterImage, Rectangle, int, bool)

ได้รับสีแพลตฟอร์มจากภาพเรสเตอร์ (ภาพแพลตฟอร์ม) ในกรณีที่ภาพไม่ได้มีหนึ่ง ในกรณีที่แพลตฟอร์มมีมันจะถูกใช้แทนที่จะดําเนินการคํานวณ

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

Parameters

image RasterImage

รูปภาพสกรู

destBounds Rectangle

จุดหมายปลายทางรูปภาพ จํากัด

entriesCount int

จํานวนรายการที่ต้องการ

useImagePalette bool

ถ้าตั้งค่ามันจะใช้แพลตฟอร์มภาพของตัวเองถ้ามี

Returns

IColorPalette

แผนสีที่เริ่มต้นด้วยสีที่พบมากที่สุดจาก image’ และมี entriesCount’ entries

GetCloseImagePalette(RasterImage, Rectangle, int, bool, สี)

ได้รับสีแพลตฟอร์มจากภาพเรสเตอร์ (ภาพแพลตฟอร์ม) ในกรณีที่ภาพไม่ได้มีหนึ่ง ในกรณีที่แพลตฟอร์มมีมันจะถูกใช้แทนที่จะดําเนินการคํานวณ

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

Parameters

image RasterImage

รูปภาพสกรู

destBounds Rectangle

จุดหมายปลายทางรูปภาพ จํากัด

entriesCount int

จํานวนรายการที่ต้องการ

useImagePalette bool

ถ้าตั้งค่ามันจะใช้แพลตฟอร์มภาพของตัวเองถ้ามี

alphaBlendInColor Color

สีที่ควรใช้เป็นสีพื้นหลังสําหรับการเปลี่ยนอัลฟาครึ่งโปร่งใส

Returns

IColorPalette

แผนสีที่เริ่มต้นด้วยสีที่พบมากที่สุดจาก image’ และมี entriesCount’ entries

GetCloseImagePalette(RasterImage, Rectangle, int, bool, สี, bool)

ได้รับสีแพลตฟอร์มจากภาพเรสเตอร์ (ภาพแพลตฟอร์ม) ในกรณีที่ภาพไม่ได้มีหนึ่ง ในกรณีที่แพลตฟอร์มมีมันจะถูกใช้แทนที่จะดําเนินการคํานวณ

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

Parameters

image RasterImage

รูปภาพสกรู

destBounds Rectangle

จุดหมายปลายทางรูปภาพ จํากัด

entriesCount int

จํานวนรายการที่ต้องการ

useImagePalette bool

ถ้าตั้งค่ามันจะใช้แพลตฟอร์มภาพของตัวเองถ้ามี

alphaBlendInColor Color

สีที่ควรใช้เป็นสีพื้นหลังสําหรับการเปลี่ยนอัลฟาครึ่งโปร่งใส

keepTransparency bool

ถ้าตั้งค่ามันจะพิจารณาอัลฟาช่อง bit ของสีภาพ

Returns

IColorPalette

แผนสีที่เริ่มต้นด้วยสีที่พบมากที่สุดจาก image’ และมี entriesCount’ entries

GetCloseTransparentImagePalette(สื่อลามก, int)

ได้รับสีแพลตฟอร์มจากภาพเรสเตอร์ (ภาพแพลตฟอร์ม) ในกรณีที่ภาพไม่ได้มีหนึ่ง ในกรณีที่แพลตฟอร์มมีมันจะถูกใช้แทนที่จะดําเนินการคํานวณ

public static IColorPalette GetCloseTransparentImagePalette(RasterImage image, int entriesCount)

Parameters

image RasterImage

รูปภาพสกรู

entriesCount int

จํานวนรายการที่ต้องการ

Returns

IColorPalette

แผนสีที่เริ่มต้นด้วยสีที่พบมากที่สุดจาก image’ และมี entriesCount’ entries

GetDownscalePalette(RasterImage)

รับ 256-สีแพลตฟอร์มซึ่งประกอบด้วย bits ด้านบนของราคาสีภาพเริ่มต้น

public static ColorPalette GetDownscalePalette(RasterImage image)

Parameters

image RasterImage

รูปภาพ

Returns

ColorPalette

The Aspose.Imaging.ColorPalette

GetUniformColorPalette(RasterImage)

รับสีสม่ําเสมอ 256 แผ่น

public static ColorPalette GetUniformColorPalette(RasterImage image)

Parameters

image RasterImage

รูปภาพ

Returns

ColorPalette

The Aspose.Imaging.ColorPalette

HasTransparentColors(คอลัมน์)

เรียนรู้ว่าแพลตฟอร์มที่ระบุมีสีโปร่งใสหรือไม่

public static bool HasTransparentColors(IColorPalette palette)

Parameters

palette IColorPalette

ปลั๊ก

Returns

bool

‘จริง’ ถ้าแพลตฟอร์มที่ระบุมีสีที่โปร่งใส ในทางกลับกัน ‘ผิดพลาด’

Exceptions

ArgumentNullException

palette’ is null.

 แบบไทย