Class ColorPaletteHelper
Nama dari : Aspose.Imaging Pengumpulan: Aspose.Imaging.dll (25.4.0)
Membantu kelas untuk manipulasi palet warna.
public static class ColorPaletteHelper
Inheritance
anggota yang diwarisi
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Methods
Create4Bit()
Membuat palet warna 4 bit.
public static IColorPalette Create4Bit()
Returns
Palet warna 4 bit.
Create4BitGrayscale(Bool)
Membuat palet 4 bit grayscale.
public static IColorPalette Create4BitGrayscale(bool minIsWhite)
Parameters
minIsWhite
bool
Jika ditempatkan untuk ‘kebenaran’ palet dimulai dengan warna putih, jika tidak ia dimulai dengan warna hitam.
Returns
4 bit palet grayscale
Create8Bit()
Membuat palet warna 8 bit.
public static IColorPalette Create8Bit()
Returns
Palet warna 8 bit.
Create8BitGrayscale(Bool)
Mencipta palet kelabu 8 bit.
public static IColorPalette Create8BitGrayscale(bool minIsWhite)
Parameters
minIsWhite
bool
Jika ditempatkan untuk ‘kebenaran’ palet dimulai dengan warna putih, jika tidak ia dimulai dengan warna hitam.
Returns
8 bit palet kelabu.
Examples
Contoh berikut membuat gambar BMP grayscale palet dan kemudian menyimpannya ke file.
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)
Dapatkan palet grayscale dari jumlah bit yang ditentukan. nilai bit yang diizinkan adalah 1, 2, 4, 8.
public static IColorPalette CreateGrayscale(int bits)
Parameters
bits
int
yang sedikit menghitung.
Returns
dengan palet grayscale.
Exceptions
bits’
CreateMonochrome()
Mencipta palet warna monochrome yang hanya mengandung 2 warna.
public static IColorPalette CreateMonochrome()
Returns
Palet warna untuk gambar monokrom.
GetCloseImagePalette(Rujukan, int)
Dapatkan palet warna dari gambar raster (palletizes gambar) jika gambar tidak memiliki satu.
public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount)
Parameters
image
RasterImage
Gambar dari raster.
entriesCount
int
Jumlah entri yang diinginkan.
Returns
Palet warna yang dimulai dengan warna yang paling umum dari image’ dan mengandung entries
entriesCount’.
Examples
Contoh berikut memuat gambar BMP dan menyimpannya kembali ke BMP menggunakan berbagai opsi simpanan.
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);
}
Contoh berikut menunjukkan bagaimana untuk memaletkan gambar BMP untuk mengurangi ukuran outputnya.
// 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, PaletteMiningMetode)
Dapatkan palet warna dari gambar raster (palletizes gambar) jika gambar tidak memiliki satu. palet akan dioptimalkan untuk kualitas gambar yang lebih baik atau diambil “AS IS” ketika PaletteMiningMethod.UseCurrentPalette digunakan.
public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount, PaletteMiningMethod paletteMiningMethod)
Parameters
image
RasterImage
Gambar dari raster.
entriesCount
int
Jumlah entri yang diinginkan.
paletteMiningMethod
PaletteMiningMethod
Metode penambangan palet.
Returns
Palet warna yang dimulai dengan warna yang paling umum dari image’ dan mengandung entries
entriesCount'.
Examples
Contoh berikut menunjukkan bagaimana untuk memampatkan gambar PNG, menggunakan warna yang diindeks dengan palet yang paling cocok
// 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)
Dapatkan palet warna dari gambar raster (palletizes gambar) jika gambar tidak memiliki satu.
public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount)
Parameters
image
RasterImage
Gambar dari raster.
destBounds
Rectangle
Gambar destinasi terbatas.
entriesCount
int
Jumlah entri yang diinginkan.
Returns
Palet warna yang dimulai dengan warna yang paling umum dari image’ dan mengandung entries
entriesCount'.
GetCloseImagePalette(RasterImage, Rectangle, int, bool)
Dapatkan palet warna dari gambar raster (palletizes gambar) jika gambar tidak memiliki satu.
public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, bool useImagePalette)
Parameters
image
RasterImage
Gambar dari raster.
destBounds
Rectangle
Gambar destinasi terbatas.
entriesCount
int
Jumlah entri yang diinginkan.
useImagePalette
bool
Jika ditetapkan, ia akan menggunakan palet gambar sendiri jika tersedia
Returns
Palet warna yang dimulai dengan warna yang paling umum dari image’ dan mengandung entries
entriesCount'.
GetCloseImagePalette(RasterImage, Rectangle, int, bool, warna)
Dapatkan palet warna dari gambar raster (palletizes gambar) jika gambar tidak memiliki satu.
public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, bool useImagePalette, Color alphaBlendInColor)
Parameters
image
RasterImage
Gambar dari raster.
destBounds
Rectangle
Gambar destinasi terbatas.
entriesCount
int
Jumlah entri yang diinginkan.
useImagePalette
bool
Jika ditetapkan, ia akan menggunakan palet gambar sendiri jika tersedia
alphaBlendInColor
Color
Warna yang harus digunakan sebagai warna latar belakang untuk pengganti alfa semi transparan.
Returns
Palet warna yang dimulai dengan warna yang paling umum dari image’ dan mengandung entries
entriesCount'.
GetCloseImagePalette(RasterImage, Rectangle, int, bool, Warna, bool)
Dapatkan palet warna dari gambar raster (palletizes gambar) jika gambar tidak memiliki satu.
public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, bool useImagePalette, Color alphaBlendInColor, bool keepTransparency)
Parameters
image
RasterImage
Gambar dari raster.
destBounds
Rectangle
Gambar destinasi terbatas.
entriesCount
int
Jumlah entri yang diinginkan.
useImagePalette
bool
Jika ditetapkan, ia akan menggunakan palet gambar sendiri jika tersedia
alphaBlendInColor
Color
Warna yang harus digunakan sebagai warna latar belakang untuk pengganti alfa semi transparan.
keepTransparency
bool
Jika ditetapkan, itu akan mempertimbangkan alpha channel bit warna gambar.
Returns
Palet warna yang dimulai dengan warna yang paling umum dari image’ dan mengandung entries
entriesCount'.
GetCloseTransparentImagePalette(Rujukan, int)
Dapatkan palet warna dari gambar raster (palletizes gambar) jika gambar tidak memiliki satu.
public static IColorPalette GetCloseTransparentImagePalette(RasterImage image, int entriesCount)
Parameters
image
RasterImage
Gambar dari raster.
entriesCount
int
Jumlah entri yang diinginkan.
Returns
Palet warna yang dimulai dengan warna yang paling umum dari image’ dan mengandung entries
entriesCount'.
GetDownscalePalette(RasterImage)
Dapatkan 256 palet warna, yang terdiri dari bit atas nilai warna gambar awal.
public static ColorPalette GetDownscalePalette(RasterImage image)
Parameters
image
RasterImage
dan gambarnya.
Returns
Ini adalah Aspose.Imaging.ColorPalette.
GetUniformColorPalette(RasterImage)
Dapatkan seragam 256 warna palet.
public static ColorPalette GetUniformColorPalette(RasterImage image)
Parameters
image
RasterImage
dan gambarnya.
Returns
Ini adalah Aspose.Imaging.ColorPalette.
HasTransparentColors(Ikonisasi)
Menentukan apakah palet yang ditentukan memiliki warna transparan.
public static bool HasTransparentColors(IColorPalette palette)
Parameters
palette
IColorPalette
dan palet.
Returns
‘kebenaran’ jika palet yang ditentukan memiliki warna transparan; jika tidak, ‘palsu’.
Exceptions
palette’ is null.