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(int)
مقدار بیتی که به آن اجازه داده می شود 1، 2، 4، 8 است.
public static IColorPalette CreateGrayscale(int bits)
Parameters
bits
int
کمی شمارش می شود.
Returns
پالت های گریس
Exceptions
bits'
CreateMonochrome()
یک پالت رنگی منحصر به فرد ایجاد می کند که حاوی تنها دو رنگ است.
public static IColorPalette CreateMonochrome()
Returns
پالت رنگی برای تصاویر مونوکروم
GetCloseImagePalette(تسنیم، int)
پالت رنگی را از تصویر راستر دریافت می کند (تصویر پالت) در صورتی که تصویر یک نباشد.در صورتی که پالت وجود داشته باشد به جای آن برای انجام محاسبات مورد استفاده قرار می گیرد.
public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount)
Parameters
image
RasterImage
تصاویری از راستر
entriesCount
int
تعداد ورودی های مورد نظر شمارش می شود.
Returns
پالت رنگی که با رایج ترین رنگ ها از تصویر " شروع می شود و حاوی ورودی های
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)
پالت رنگی را از تصویر راستر دریافت می کند (تصویر پالت) در صورتی که تصویر یک نباشد.پالت در حال بهینه سازی برای کیفیت تصویر بهتر فهرست شده است یا در هنگام استفاده از PaletteMiningMethod.UseCurrent
public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount, PaletteMiningMethod paletteMiningMethod)
Parameters
image
RasterImage
تصاویری از راستر
entriesCount
int
تعداد ورودی های مورد نظر شمارش می شود.
paletteMiningMethod
PaletteMiningMethod
روش معدن پالت
Returns
پالت رنگی که با رایج ترین رنگ ها از تصویر " شروع می شود و حاوی ورودی های
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
پالت رنگی که با رایج ترین رنگ ها از تصویر " شروع می شود و حاوی ورودی های
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
پالت رنگی که با رایج ترین رنگ ها از تصویر " شروع می شود و حاوی ورودی های
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
پالت رنگی که با رایج ترین رنگ ها از تصویر " شروع می شود و حاوی ورودی های
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
پالت رنگی که با رایج ترین رنگ ها از تصویر " شروع می شود و حاوی ورودی های
entriesCount است.
GetCloseTransparentImagePalette(تسنیم، int)
پالت رنگی را از تصویر راستر دریافت می کند (تصویر پالت) در صورتی که تصویر یک نباشد.در صورتی که پالت وجود داشته باشد به جای آن برای انجام محاسبات مورد استفاده قرار می گیرد.
public static IColorPalette GetCloseTransparentImagePalette(RasterImage image, int entriesCount)
Parameters
image
RasterImage
تصاویری از راستر
entriesCount
int
تعداد ورودی های مورد نظر شمارش می شود.
Returns
پالت رنگی که با رایج ترین رنگ ها از تصویر " شروع می شود و حاوی ورودی های
entriesCount است.
GetDownscalePalette(RasterImage)
به دست آوردن پالت رنگی 256، متشکل از بیت های بالا از ارزش های رنگی تصویر اولیه.
public static ColorPalette GetDownscalePalette(RasterImage image)
Parameters
image
RasterImage
این تصویر .
Returns
آرشیو برچسب ها: آرشیو آرشیو آرشیو آرشیو
GetUniformColorPalette(RasterImage)
یک پالت رنگی 256 رنگ داشته باشید.
public static ColorPalette GetUniformColorPalette(RasterImage image)
Parameters
image
RasterImage
این تصویر .
Returns
آرشیو برچسب ها: آرشیو آرشیو آرشیو آرشیو
HasTransparentColors(رنگ آمیزی)
تعیین می کند که آیا پالت مشخص شده دارای رنگ های شفاف است.
public static bool HasTransparentColors(IColorPalette palette)
Parameters
palette
IColorPalette
پالت است.
Returns
“واقعی” اگر پالت مشخص شده دارای رنگ های شفاف است؛ در غیر این صورت، “دروغ” است.
Exceptions
palette’ is null.