Class ColorPaletteHelper

Class ColorPaletteHelper

이름 공간 : Aspose.Imaging 모임: Aspose.Imaging.dll (25.4.0)

색상 팔레트 조작을위한 도우미 클래스.

public static class ColorPaletteHelper

Inheritance

object ColorPaletteHelper

상속 회원들

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

IColorPalette

4비트 색상 패널

Create4BitGrayscale(바울)

4비트 그레이스케일 팔레트를 만듭니다.

public static IColorPalette Create4BitGrayscale(bool minIsWhite)

Parameters

minIsWhite bool

‘진실’으로 설정하면 팔레트는 흰색으로 시작되며, 그렇지 않으면 검은색으로 시작됩니다.

Returns

IColorPalette

4비트 그레이스케일 팔레트

Create8Bit()

8비트 색상 패널을 만듭니다.

public static IColorPalette Create8Bit()

Returns

IColorPalette

8비트 색상 패널

Create8BitGrayscale(바울)

8비트 그레이스케일 팔레트를 만듭니다.

public static IColorPalette Create8BitGrayscale(bool minIsWhite)

Parameters

minIsWhite bool

‘진실’으로 설정하면 팔레트는 흰색으로 시작되며, 그렇지 않으면 검은색으로 시작됩니다.

Returns

IColorPalette

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

IColorPalette

그레이스케일 팔레트

Exceptions

ArgumentOutOfRangeException

bits’

CreateMonochrome()

그것은 단지 2 개의 색상을 포함하는 단색 색상 패널을 만듭니다.

public static IColorPalette CreateMonochrome()

Returns

IColorPalette

모노크롬 이미지에 대한 색상 패널.

GetCloseImagePalette(라스테르 이미지, int)

그림이 하나가 없는 경우에 라스터 이미지에서 색상 팔레트를 얻습니다. 팔레트가 존재하는 경우에는 대신 계산을 수행하는 데 사용됩니다.

public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount)

Parameters

image RasterImage

라스터 이미지 입니다.

entriesCount int

원하는 항목을 계산합니다.

Returns

IColorPalette

색상 패널은 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)

그림이 하나가 없는 경우에 라스터 이미지에서 색상 팔레트를 얻습니다. 팔레트는 더 나은 인덱스 된 이미지 품질을 위해 최적화되거나 PaletteMiningMethod.UseCurrentPalette를 사용할 때 “AS IS"를 취합니다.

public static IColorPalette GetCloseImagePalette(RasterImage image, int entriesCount, PaletteMiningMethod paletteMiningMethod)

Parameters

image RasterImage

라스터 이미지 입니다.

entriesCount int

원하는 항목을 계산합니다.

paletteMiningMethod PaletteMiningMethod

팔레트 광산 방법

Returns

IColorPalette

색상 패널은 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

IColorPalette

색상 패널은 image’에서 가장 흔한 색상으로 시작하여 entriesCount’ 입력을 포함합니다.

GetCloseImagePalette(라스테리 이미지, 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

IColorPalette

색상 패널은 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

IColorPalette

색상 패널은 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

IColorPalette

색상 패널은 image’에서 가장 흔한 색상으로 시작하여 entriesCount’ 입력을 포함합니다.

GetCloseTransparentImagePalette(라스테르 이미지, int)

그림이 하나가 없는 경우에 라스터 이미지에서 색상 팔레트를 얻습니다. 팔레트가 존재하는 경우에는 대신 계산을 수행하는 데 사용됩니다.

public static IColorPalette GetCloseTransparentImagePalette(RasterImage image, int entriesCount)

Parameters

image RasterImage

라스터 이미지 입니다.

entriesCount int

원하는 항목을 계산합니다.

Returns

IColorPalette

색상 패널은 image’에서 가장 흔한 색상으로 시작하여 entriesCount’ 입력을 포함합니다.

GetDownscalePalette(RasterImage)

256 색상 패널을 얻으십시오, 초기 이미지 색상 값의 상단 비트로 구성됩니다.

public static ColorPalette GetDownscalePalette(RasterImage image)

Parameters

image RasterImage

그 이미지 입니다.

Returns

ColorPalette

아스포스.Imaging.ColorPalette

GetUniformColorPalette(RasterImage)

동일한 256 색상 패널을 얻으십시오.

public static ColorPalette GetUniformColorPalette(RasterImage image)

Parameters

image RasterImage

그 이미지 입니다.

Returns

ColorPalette

아스포스.Imaging.ColorPalette

HasTransparentColors(아이콜라 패널)

지정된 패널이 투명한 색상이 있는지 여부를 결정합니다.

public static bool HasTransparentColors(IColorPalette palette)

Parameters

palette IColorPalette

이 팔레트

Returns

bool

‘진실’은 지정된 패널이 투명한 색상이 있는 경우; 그렇지 않으면 ‘거짓’입니다.

Exceptions

ArgumentNullException

palette’ is null.

 한국어