Class ColorPaletteHelper
Името на пространството: Aspose.Imaging Асамблея: Aspose.Imaging.dll (25.4.0)
Помощна класа за манипулация на цветовите палети.
public static class ColorPaletteHelper
Inheritance
наследници
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Methods
Create4Bit()
Създава 4 бита цветна палитра.
public static IColorPalette Create4Bit()
Returns
4 цветни палитра.
Create4BitGrayscale(Боул)
Създава 4 бита грейскална палитра.
public static IColorPalette Create4BitGrayscale(bool minIsWhite)
Parameters
minIsWhite
bool
Ако се зададе за “истински”, палетът започва с бял цвят, в противен случай започва със черен цвят.
Returns
4 бита грейскална палитра.
Create8Bit()
Създава осем-битната цветна палитра.
public static IColorPalette Create8Bit()
Returns
8 бита цветна палета.
Create8BitGrayscale(Боул)
Създава осем-битната грейскална палитра.
public static IColorPalette Create8BitGrayscale(bool minIsWhite)
Parameters
minIsWhite
bool
Ако се зададе за “истински”, палетът започва с бял цвят, в противен случай започва със черен цвят.
Returns
8 бита грейскална палитра.
Examples
Следващият пример създава палетизирана граискална BMP картина и след това я съхранява в файл.
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(инт)
Получава палетата на гравитацията на посочения брой битове. допустимите стойности на битите са 1, 2, 4, 8.
public static IColorPalette CreateGrayscale(int bits)
Parameters
bits
int
Малкото броене.
Returns
Грейскална палитра
Exceptions
bits'
CreateMonochrome()
Създава монохромна цветова палитра, съдържаща само 2 цветове.
public static IColorPalette CreateMonochrome()
Returns
Цветна палитра за монохромни изображения.
GetCloseImagePalette(Снимка, инт)
Получава цветна палета от изображението на растер (палетизира изображение) в случай, че снимката няма една.
public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount)
Parameters
image
RasterImage
Изображението на Растер.
entriesCount
int
Изброяват се желаните входове.
Returns
Палетата на цветовете, която започва с най-често срещаните цветове от изображението и съдържа вноските на “Counter”.
Examples
Следващият пример зарежда изображение на 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);
}
Следващият пример показва как да палетизирате 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(РастерИмаж, инт, ПалетМининг Метод)
Палетът ще бъде оптимизиран за по-добро индексирано качество на изображението или “AS IS”, когато PaletteMiningMethod.UseCurrentPalette се използва.
public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount, PaletteMiningMethod paletteMiningMethod)
Parameters
image
RasterImage
Изображението на Растер.
entriesCount
int
Изброяват се желаните входове.
paletteMiningMethod
PaletteMiningMethod
Методът на изкопаемост на палета.
Returns
Палетата на цветовете, която започва с най-често срещаните цветове от изображението и съдържа вноските на “Counter”.
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(РастерИмаж, Ректангъл, инт)
Получава цветна палета от изображението на растер (палетизира изображение) в случай, че снимката няма една.
public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount)
Parameters
image
RasterImage
Изображението на Растер.
destBounds
Rectangle
Снимката на дестинацията е ограничена.
entriesCount
int
Изброяват се желаните входове.
Returns
Палетата на цветовете, която започва с най-често срещаните цветове от изображението и съдържа вноските на “Counter”.
GetCloseImagePalette(RasterImage, Rectangle, инт, боол)
Получава цветна палета от изображението на растер (палетизира изображение) в случай, че снимката няма една.
public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, bool useImagePalette)
Parameters
image
RasterImage
Изображението на Растер.
destBounds
Rectangle
Снимката на дестинацията е ограничена.
entriesCount
int
Изброяват се желаните входове.
useImagePalette
bool
Ако е зададен, той ще използва собствената си палетка на изображенията, ако е налице
Returns
Палетата на цветовете, която започва с най-често срещаните цветове от изображението и съдържа вноските на “Counter”.
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
Палетата на цветовете, която започва с най-често срещаните цветове от изображението и съдържа вноските на “Counter”.
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
Ако е зададено, то ще разгледа алфа-каналните битове на цветовете на изображението.
Returns
Палетата на цветовете, която започва с най-често срещаните цветове от изображението и съдържа вноските на “Counter”.
GetCloseTransparentImagePalette(Снимка, инт)
Получава цветна палета от изображението на растер (палетизира изображение) в случай, че снимката няма една.
public static IColorPalette GetCloseTransparentImagePalette(RasterImage image, int entriesCount)
Parameters
image
RasterImage
Изображението на Растер.
entriesCount
int
Изброяват се желаните входове.
Returns
Палетата на цветовете, която започва с най-често срещаните цветове от изображението и съдържа вноските на “Counter”.
GetDownscalePalette(RasterImage)
Получете 256 цветни палети, състоящи се от горните битове на първоначалните стойности на цветовете на изображението.
public static ColorPalette GetDownscalePalette(RasterImage image)
Parameters
image
RasterImage
Името е.
Returns
Забележка на Aspose.Imaging.ColorPalette.
GetUniformColorPalette(RasterImage)
Вземете универсална 256 цветна палитра.
public static ColorPalette GetUniformColorPalette(RasterImage image)
Parameters
image
RasterImage
Името е.
Returns
Забележка на Aspose.Imaging.ColorPalette.
HasTransparentColors(ICOLORПалате)
Определя дали посочената палитра има прозрачни цветове.
public static bool HasTransparentColors(IColorPalette palette)
Parameters
palette
IColorPalette
За палетата
Returns
“истински” ако посочената палета има прозрачни цветове; в противен случай, “фалшиви”.
Exceptions
palette’ is null.