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
下記の例は、パレットされたグレイスケールの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(レイアウト、 int)
色パレットはラスター画像(画像をパレット化する)から得られますが、画像が1つがない場合は、パレットが存在する場合は、その代わりに計算を行うために使用されます。
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(ラスターイメージ, int, PaletteMiningMethod)
パレットは、画像が1つを持っていない場合、ラスター画像から色パレットを取得します。パレットは、より良いインデックスされた画像の品質のために最適化されるか、PalletMiningMethod.UseCurrentPaletteを使用するときに「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)
色パレットはラスター画像(画像をパレット化する)から得られますが、画像が1つがない場合は、パレットが存在する場合は、その代わりに計算を行うために使用されます。
public static IColorPalette GetCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount)
Parameters
image
RasterImage
ラスター画像
destBounds
Rectangle
目的地画像の制限
entriesCount
int
望ましい入り口を数える。
Returns
色パレットは、 image’ から最も頻繁な色で始まり、
entriesCount’ のエントリーが含まれています。
GetCloseImagePalette(ラスターイメージ、レクトアンゲル、int、bool)
色パレットはラスター画像(画像をパレット化する)から得られますが、画像が1つがない場合は、パレットが存在する場合は、その代わりに計算を行うために使用されます。
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、カラー)
色パレットはラスター画像(画像をパレット化する)から得られますが、画像が1つがない場合は、パレットが存在する場合は、その代わりに計算を行うために使用されます。
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)
色パレットはラスター画像(画像をパレット化する)から得られますが、画像が1つがない場合は、パレットが存在する場合は、その代わりに計算を行うために使用されます。
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(レイアウト、 int)
色パレットはラスター画像(画像をパレット化する)から得られますが、画像が1つがない場合は、パレットが存在する場合は、その代わりに計算を行うために使用されます。
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
アスポーズ.Imaging.ColorPalette
GetUniformColorPalette(RasterImage)
ユニフォーム256色パレットを取得します。
public static ColorPalette GetUniformColorPalette(RasterImage image)
Parameters
image
RasterImage
イメージです。
Returns
アスポーズ.Imaging.ColorPalette
HasTransparentColors(アイコンパレット)
指定されたパレットが透明な色を持っているかどうかを決定します。
public static bool HasTransparentColors(IColorPalette palette)
Parameters
palette
IColorPalette
パレット
Returns
「真実」は、指定されたパレットが透明な色を持っている場合、そうでなければ「偽物」です。
Exceptions
palette’ is null.