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()
Креирају палету боја од 8 бит.
public static IColorPalette Create8Bit()
Returns
8 бита боја палета.
Create8BitGrayscale(Боол)
Креира 8 бита грејскале палете.
public static IColorPalette Create8BitGrayscale(bool minIsWhite)
Parameters
minIsWhite
bool
Ако је постављен на “истину”, палет почиње са белом бојом, иначе почиње са црном бојом.
Returns
8 бита грискалне палете.
Examples
Следећи пример ствара палетизовану слику БМП и затим га чува у датотеку.
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
Poželjna ulaznica se broji.
Returns
Палет боја који почиње са најчешћим бојама из image’ и садржи
entriesCount’ улоге.
Examples
Следећи пример преузима БМП слику и спасава га назад на БМП користећи различите опције за сачување.
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);
}
Следећи пример показује како палетизовати БМП слику како би се смањила његова величина излаза.
// 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(РастерИмаге, инт, ПалетМинингМетод)
Добије боју палете из растер слике (палетезира слику) у случају да слика нема једну. Палете је близу да се оптимизује за бољу индексирану квалитет имовине или узети “АС ИС” када се користи PaletteMiningMethod.UseCurrentPalette.
public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount, PaletteMiningMethod paletteMiningMethod)
Parameters
image
RasterImage
На слици растер.
entriesCount
int
Poželjna ulaznica se broji.
paletteMiningMethod
PaletteMiningMethod
Палетни метод рударства.
Returns
Палет боја који почиње са најчешћим бојама из image’ и садржи
entriesCount’ улоге.
Examples
Следећи пример показује како компресирати ПНГ слику, користећи индексирану боју са најбољим палетом
// 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
Poželjna ulaznica se broji.
Returns
Палет боја који почиње са најчешћим бојама из image’ и садржи
entriesCount’ улоге.
GetCloseImagePalette(RasterImage, Rectangle, int, bool)
Добије боју палете из растер слике (палетез слике) у случају да слика нема једну.
public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, bool useImagePalette)
Parameters
image
RasterImage
На слици растер.
destBounds
Rectangle
Дестинација слике ограничава.
entriesCount
int
Poželjna ulaznica se broji.
useImagePalette
bool
Ако је постављен, користиће сопствену палету слике ако је доступна
Returns
Палет боја који почиње са најчешћим бојама из image’ и садржи
entriesCount’ улоге.
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
Poželjna ulaznica se broji.
useImagePalette
bool
Ако је постављен, користиће сопствену палету слике ако је доступна
alphaBlendInColor
Color
Боја која треба користити као боја позадине за полупрозрачну алфа замену.
Returns
Палет боја који почиње са најчешћим бојама из image’ и садржи
entriesCount’ улоге.
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
Poželjna ulaznica se broji.
useImagePalette
bool
Ако је постављен, користиће сопствену палету слике ако је доступна
alphaBlendInColor
Color
Боја која треба користити као боја позадине за полупрозрачну алфа замену.
keepTransparency
bool
Ако је постављен, то ће размотрити алфа канал бита слике боје.
Returns
Палет боја који почиње са најчешћим бојама из image’ и садржи
entriesCount’ улоге.
GetCloseTransparentImagePalette(РастерИмаге, инт)
Добије боју палете из растер слике (палетез слике) у случају да слика нема једну.
public static IColorPalette GetCloseTransparentImagePalette(RasterImage image, int entriesCount)
Parameters
image
RasterImage
На слици растер.
entriesCount
int
Poželjna ulaznica se broji.
Returns
Палет боја који почиње са најчешћим бојама из image’ и садржи
entriesCount’ улоге.
GetDownscalePalette(RasterImage)
Добијте палету од 256 боја, која се састоји од врхунских бита оригиналних вредности боје слике.
public static ColorPalette GetDownscalePalette(RasterImage image)
Parameters
image
RasterImage
и слику .
Returns
WL17_.Цветна палета
GetUniformColorPalette(RasterImage)
Добијте јединствену палету од 256 боја.
public static ColorPalette GetUniformColorPalette(RasterImage image)
Parameters
image
RasterImage
и слику .
Returns
WL17_.Цветна палета
HasTransparentColors(ИЦОЛОРПАЛЕТ)
Одређује да ли одређена палета има транспарентне боје.
public static bool HasTransparentColors(IColorPalette palette)
Parameters
palette
IColorPalette
То је палет.
Returns
‘истина’ ако наведена палета има транспарентне боје; иначе, ‘фалсификована’.
Exceptions
palette’ is null.