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
أربعة أجزاء من اللون.
Create4BitGrayscale(بول)
يخلق لوحة 4 بوصة رمادية.
public static IColorPalette Create4BitGrayscale(bool minIsWhite)
Parameters
minIsWhite
bool
إذا قمت بتعيين “الحقيقي” يبدأ اللوحة باللون الأبيض ، وإلا يبدأ باللون الأسود.
Returns
أربعة أجزاء من البلاط الرمادي
Create8Bit()
يخلق لوحة الألوان 8 بت.
public static IColorPalette Create8Bit()
Returns
ثمانية أجزاء من الألوان.
Create8BitGrayscale(بول)
يخلق 8 بت البلاط الرمادي.
public static IColorPalette Create8BitGrayscale(bool minIsWhite)
Parameters
minIsWhite
bool
إذا قمت بتعيين “الحقيقي” يبدأ اللوحة باللون الأبيض ، وإلا يبدأ باللون الأسود.
Returns
ثمانية أجزاء من البلاط الرمادي
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
اللوحة اللوحية للصور monochrome.
GetCloseImagePalette(الرموز، إنت)
يحصل على لوحة الألوان من الصورة (اللوحة) في حالة عدم وجود الصورة واحدة.في حالة وجود لوحة سيتم استخدامه بدلا من إجراء الحسابات.
public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount)
Parameters
image
RasterImage
الصورة الرائعة
entriesCount
int
عدد الإدخالات المطلوبة.
Returns
اللوحة الألوان التي تبدأ بالألوان الأكثر شيوعا من image’ وتحتوي على
entriesCount’ إدخالات.
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);
}
يظهر المثال التالي كيفية تصفية صورة 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)
يحصل على لوحة الألوان من الصورة المطاطية (الصورة المطاطية) في حالة عدم وجود الصورة واحدة.اللوحة على وشك أن يتم تحسينها لتحسين جودة الصورة المعدلة أو أخذ “AS IS” عندما يتم استخدام لوحة الألوان المطاطية.
public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount, PaletteMiningMethod paletteMiningMethod)
Parameters
image
RasterImage
الصورة الرائعة
entriesCount
int
عدد الإدخالات المطلوبة.
paletteMiningMethod
PaletteMiningMethod
طريقة التعدين الباليه.
Returns
اللوحة الألوان التي تبدأ بالألوان الأكثر شيوعا من image’ وتحتوي على
entriesCount’ إدخالات.
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(الفوركس، Rectangle، int)
يحصل على لوحة الألوان من الصورة (اللوحة) في حالة عدم وجود الصورة واحدة.في حالة وجود لوحة سيتم استخدامه بدلا من إجراء الحسابات.
public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount)
Parameters
image
RasterImage
الصورة الرائعة
destBounds
Rectangle
الحد الأدنى للصورة الوجهة.
entriesCount
int
عدد الإدخالات المطلوبة.
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
عدد الإدخالات المطلوبة.
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
عدد الإدخالات المطلوبة.
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
عدد الإدخالات المطلوبة.
useImagePalette
bool
إذا تم إعدادها ، فستستخدم لوحة الصورة الخاصة بها إذا كانت متوفرة
alphaBlendInColor
Color
اللون الذي ينبغي استخدامه كألوان خلفية لاستبدال ألفا شبه شفاف.
keepTransparency
bool
إذا وضعت، فإنه سوف يأخذ في الاعتبار ألفا قناة بيت من ألوان الصورة.
Returns
اللوحة الألوان التي تبدأ بالألوان الأكثر شيوعا من image’ وتحتوي على
entriesCount’ إدخالات.
GetCloseTransparentImagePalette(الرموز، إنت)
يحصل على لوحة الألوان من الصورة (اللوحة) في حالة عدم وجود الصورة واحدة.في حالة وجود لوحة سيتم استخدامه بدلا من إجراء الحسابات.
public static IColorPalette GetCloseTransparentImagePalette(RasterImage image, int entriesCount)
Parameters
image
RasterImage
الصورة الرائعة
entriesCount
int
عدد الإدخالات المطلوبة.
Returns
اللوحة الألوان التي تبدأ بالألوان الأكثر شيوعا من image’ وتحتوي على
entriesCount’ إدخالات.
GetDownscalePalette(RasterImage)
احصل على لوحة 256 لونًا تتألف من النقاط العليا من قيم الألوان الأصلية للصورة.
public static ColorPalette GetDownscalePalette(RasterImage image)
Parameters
image
RasterImage
في الصورة .
Returns
فيديوهات متعلقة بـ “ ColorPalette ”
GetUniformColorPalette(RasterImage)
احصل على 256 ملعقة من الألوان
public static ColorPalette GetUniformColorPalette(RasterImage image)
Parameters
image
RasterImage
في الصورة .
Returns
فيديوهات متعلقة بـ “ ColorPalette ”
HasTransparentColors(ICOLORPALET)
يحدد ما إذا كانت اللوحة المحددة لها ألوان شفافة.
public static bool HasTransparentColors(IColorPalette palette)
Parameters
palette
IColorPalette
على اللوحة .
Returns
“حقيقي” إذا كانت اللوحة المحددة لها ألوان شفافة؛ وإلا، “مزيفة”.
Exceptions
palette’ is null.