ColorPaletteHelper

Inheritance: java.lang.Object

public final class ColorPaletteHelper

فئة مساعدة لتعديل لوحة الألوان.

الطرق

طريقةالوصف
createMonochrome()ينشئ لوحة ألوان أحادية اللون تحتوي على لونين فقط.
create4Bit()ينشئ لوحة ألوان 4 بت.
create4BitGrayscale(boolean minIsWhite)ينشئ لوحة تدرج رمادي 4 بت.
create8Bit()ينشئ لوحة ألوان 8 بت.
create8BitGrayscale(boolean minIsWhite)ينشئ لوحة تدرج رمادي 8 بت.
getCloseImagePalette(RasterImage image, int entriesCount)يحصل على لوحة ألوان من صورة نقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة.
getCloseTransparentImagePalette(RasterImage image, int entriesCount)يحصل على لوحة ألوان من صورة نقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة.
getCloseImagePalette(RasterImage image, int entriesCount, int paletteMiningMethod)يحصل على لوحة ألوان من صورة نقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة.
getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount)يحصل على لوحة ألوان من صورة نقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة.
getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, boolean useImagePalette)يحصل على لوحة ألوان من صورة نقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة.
getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, boolean useImagePalette, Color alphaBlendInColor)يحصل على لوحة ألوان من صورة نقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة.
getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, boolean useImagePalette, Color alphaBlendInColor, boolean keepTransparency)يحصل على لوحة ألوان من صورة نقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة.
getUniformColorPalette(RasterImage image)احصل على لوحة ألوان موحدة مكوّنة من 256 لونًا.
getDownscalePalette(RasterImage image)احصل على لوحة ألوان مكوّنة من 256 لونًا، مكوّنة من البتات العليا لقيم ألوان الصورة الأصلية.
hasTransparentColors(IColorPalette palette)يحدد ما إذا كانت اللوحة المحددة تحتوي على ألوان شفافة.
createGrayscale(int bits)يحصل على لوحة تدرج رمادي لعدد البتات المحدد.

createMonochrome()

public static IColorPalette createMonochrome()

ينشئ لوحة ألوان أحادية اللون تحتوي على لونين فقط.

Returns: IColorPalette - Color palette for monochrome images.

create4Bit()

public static IColorPalette create4Bit()

ينشئ لوحة ألوان 4 بت.

Returns: IColorPalette - The 4 bit color palette.

create4BitGrayscale(boolean minIsWhite)

public static IColorPalette create4BitGrayscale(boolean minIsWhite)

ينشئ لوحة تدرج رمادي 4 بت.

Parameters:

معاملنوعالوصف
minIsWhitebooleanإذا تم تعيينه إلى true تبدأ اللوحة باللون الأبيض، وإلا تبدأ باللون الأسود.

Returns: IColorPalette - The 4 bit grayscale palette.

create8Bit()

public static IColorPalette create8Bit()

ينشئ لوحة ألوان 8 بت.

Returns: IColorPalette - The 8bit color palette.

create8BitGrayscale(boolean minIsWhite)

public static IColorPalette create8BitGrayscale(boolean minIsWhite)

ينشئ لوحة تدرج رمادي 8 بت.

Parameters:

معاملنوعالوصف
minIsWhitebooleanإذا تم تعيينه إلى true تبدأ اللوحة باللون الأبيض، وإلا تبدأ باللون الأسود.

Returns: IColorPalette - The 8 bit grayscale palette.

Example: The following example creates a palettized grayscale BMP image and then saves it to a file.

String dir = "c:\\temp\\";

com.aspose.imaging.imageoptions.BmpOptions createOptions = new com.aspose.imaging.imageoptions.BmpOptions();

// احفظ إلى ملف
createOptions.setSource(new com.aspose.imaging.sources.FileCreateSource(dir + "output.palette8bit.bmp", false));

// استخدم 8 بت لكل بكسل لتقليل حجم الصورة الناتجة.
createOptions.setBitsPerPixel(8);

// عيّن لوحة تدرج رمادي قياسية 8 بت تغطي جميع ألوان التدرج الرمادي.
// إذا كانت الصورة المعالجة تحتوي فقط على ألوان تدرج الرمادي، فإن إصدارها المصفوف
// يبدو بصريًا غير قابل للتمييز عن نسخة غير مصفوفة.
createOptions.setPalette(com.aspose.imaging.ColorPaletteHelper.create8BitGrayscale(false));

// احفظ دون ضغط.
// يمكنك أيضًا استخدام ضغط RLE-8 لتقليل حجم الصورة الناتجة.
createOptions.setCompression(com.aspose.imaging.fileformats.bmp.BitmapCompression.Rgb);

// اضبط الدقة الأفقية والعمودية إلى 96 نقطة في البوصة.
createOptions.setResolutionSettings(new com.aspose.imaging.ResolutionSetting(96.0, 96.0));

// أنشئ صورة BMP بحجم 100 × 100 بكسل واحفظها في ملف.
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(createOptions, 100, 100);
try {
    com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);

    com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush(
            new com.aspose.imaging.Point(0, 0),
            new com.aspose.imaging.Point(image.getWidth(), image.getHeight()),
            com.aspose.imaging.Color.getBlack(),
            com.aspose.imaging.Color.getWhite());

    // املأ الصورة بتدرج رمادي
    graphics.fillRectangle(gradientBrush, image.getBounds());

    image.save();
} finally {
    image.dispose();
}

getCloseImagePalette(RasterImage image, int entriesCount)

public static IColorPalette getCloseImagePalette(RasterImage image, int entriesCount)

يحصل على لوحة ألوان من الصورة النقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة. إذا كانت اللوحة موجودة، سيتم استخدامها بدلاً من إجراء الحسابات.

Parameters:

معاملنوعالوصف
imageRasterImageالصورة النقطية.
entriesCountintعدد الإدخالات المطلوب.

Returns: IColorPalette - The color palette which starts with the most frequent colors from the image and contains entriesCount entries.

Example: The following example shows how to palletize a BMP image to reduce its output size.


// إنشاء صورة BMP بحجم 100 × 100 بكسل.
com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(100, 100);
try {
    // التدرج الخطي من الزاوية اليسرى العليا إلى الزاوية اليمنى السفلى للصورة.
    com.aspose.imaging.brushes.LinearGradientBrush brush =
            new com.aspose.imaging.brushes.LinearGradientBrush(
                    new com.aspose.imaging.Point(0, 0),
                    new com.aspose.imaging.Point(bmpImage.getWidth(), bmpImage.getHeight()),
                    com.aspose.imaging.Color.getRed(),
                    com.aspose.imaging.Color.getGreen());

    // ملء الصورة بالكامل بفرشاة التدرج الخطي.
    com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(bmpImage);
    gr.fillRectangle(brush, bmpImage.getBounds());

    // احصل على أقرب لوحة ألوان 8‑بت تغطي أكبر عدد ممكن من البكسلات، بحيث تكون الصورة مُلوَّنة بلوحة ألوان.
    // يكاد يكون غير قابل للتمييز بصريًا عن نسخة غير ملوّنة.
    com.aspose.imaging.IColorPalette palette = com.aspose.imaging.ColorPaletteHelper.getCloseImagePalette(bmpImage, 256);

    // تحتوي لوحة الألوان 8-bit على ما لا يزيد عن 256 لونًا.
    com.aspose.imaging.imageoptions.BmpOptions saveOptions = new com.aspose.imaging.imageoptions.BmpOptions();
    saveOptions.setPalette(palette);
    saveOptions.setBitsPerPixel(8);

    java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();
    try {
        bmpImage.save(stream, saveOptions);
        System.out.println("The palettized image size is " + stream.size() + " bytes.");
    } finally {
        stream.close();
    }

    stream = new java.io.ByteArrayOutputStream();
    try {
        bmpImage.save(stream);
        System.out.println("The non-palettized image size is " + stream.size() + " bytes.");
    } finally {
        stream.close();
    }
} finally {
    bmpImage.dispose();
}

// المخرجات تبدو هكذا:
// حجم الصورة الملونة باللوحة هو 11078 بايت.
// حجم الصورة غير الملونة باللوحة هو 40054 بايت.

getCloseTransparentImagePalette(RasterImage image, int entriesCount)

public static IColorPalette getCloseTransparentImagePalette(RasterImage image, int entriesCount)

يحصل على لوحة ألوان من الصورة النقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة. إذا كانت اللوحة موجودة، سيتم استخدامها بدلاً من إجراء الحسابات.

Parameters:

معاملنوعالوصف
imageRasterImageالصورة النقطية.
entriesCountintعدد الإدخالات المطلوب.

Returns: IColorPalette - The color palette which starts with the most frequent colors from the image and contains entriesCount entries.

getCloseImagePalette(RasterImage image, int entriesCount, int paletteMiningMethod)

public static IColorPalette getCloseImagePalette(RasterImage image, int entriesCount, int paletteMiningMethod)

يحصل على لوحة ألوان من الصورة النقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة. سيتم تحسين اللوحة للحصول على جودة صورة مفهرسة أفضل أو تُؤخذ “AS IS” عندما يُستخدم PaletteMiningMethod.UseCurrentPalette.

Parameters:

معاملنوعالوصف
imageRasterImageالصورة النقطية.
entriesCountintعدد الإدخالات المطلوب.
paletteMiningMethodintطريقة استخراج لوحة الألوان.

Returns: IColorPalette - The color palette which starts with the most frequent colors from the image and contains entriesCount entries.

Example: The following example shows how to compress a PNG image, using indexed color with best fit palette


// يحمّل صورة png        
String sourceFilePath = "OriginalRings.png";
String outputFilePath = "OriginalRingsOutput.png";
try (com.aspose.imaging.Image image = com.aspose.imaging.Image.load(sourceFilePath))
{
    com.aspose.imaging.imageoptions.PngOptions options = new com.aspose.imaging.imageoptions.PngOptions();
    options.setProgressive(true);
    // استخدم نوع اللون المفهرس
    options.setColorType(com.aspose.imaging.fileformats.png.PngColorType.IndexedColor);
    // استخدم أقصى ضغط
    options.setCompressionLevel(9);
    // احصل على أقرب لوحة ألوان 8‑بت تغطي أكبر عدد ممكن من البكسلات، بحيث تكون الصورة مُلوَّنة بلوحة ألوان.
    // يكاد يكون غير قابل للتمييز بصريًا عن نسخة غير ملوّنة.
    options.setPalette(com.aspose.imaging.ColorPaletteHelper.getCloseImagePalette((com.aspose.imaging.RasterImage)image, 
                                256, Aspose.Imaging.PaletteMiningMethod.Histogram));
                     
    image.save(outputFilePath, options);
}
// يجب تقليل حجم ملف الإخراج بشكل كبير

getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount)

public static IColorPalette getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount)

يحصل على لوحة ألوان من الصورة النقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة. إذا كانت اللوحة موجودة، سيتم استخدامها بدلاً من إجراء الحسابات.

Parameters:

معاملنوعالوصف
imageRasterImageالصورة النقطية.
destBoundsRectangleحدود الصورة الوجهة.
entriesCountintعدد الإدخالات المطلوب.

Returns: IColorPalette - The color palette which starts with the most frequent colors from the image and contains entriesCount entries.

getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, boolean useImagePalette)

public static IColorPalette getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, boolean useImagePalette)

يحصل على لوحة ألوان من الصورة النقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة. إذا كانت اللوحة موجودة، سيتم استخدامها بدلاً من إجراء الحسابات.

Parameters:

معاملنوعالوصف
imageRasterImageالصورة النقطية.
destBoundsRectangleحدود الصورة الوجهة.
entriesCountintعدد الإدخالات المطلوب.
useImagePalettebooleanإذا تم تعيينه، سيستخدم لوحة ألوان الصورة الخاصة به إذا كانت متوفرة

Returns: IColorPalette - The color palette which starts with the most frequent colors from the image and contains entriesCount entries.

getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, boolean useImagePalette, Color alphaBlendInColor)

public static IColorPalette getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, boolean useImagePalette, Color alphaBlendInColor)

يحصل على لوحة ألوان من الصورة النقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة. إذا كانت اللوحة موجودة، سيتم استخدامها بدلاً من إجراء الحسابات.

Parameters:

معاملنوعالوصف
imageRasterImageالصورة النقطية.
destBoundsRectangleحدود الصورة الوجهة.
entriesCountintعدد الإدخالات المطلوب.
useImagePalettebooleanإذا تم تعيينه، سيستخدم لوحة ألوان الصورة الخاصة به إذا كانت متوفرة
alphaBlendInColorColorاللون الذي يجب استخدامه كلون خلفية لاستبدال ألفا شبه الشفاف.

Returns: IColorPalette - The color palette which starts with the most frequent colors from the image and contains entriesCount entries.

getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, boolean useImagePalette, Color alphaBlendInColor, boolean keepTransparency)

public static IColorPalette getCloseImagePalette(RasterImage image, Rectangle destBounds, int entriesCount, boolean useImagePalette, Color alphaBlendInColor, boolean keepTransparency)

يحصل على لوحة ألوان من الصورة النقطية (يحوّل الصورة إلى لوحة ألوان) في حال عدم وجود لوحة ألوان للصورة. إذا كانت اللوحة موجودة، سيتم استخدامها بدلاً من إجراء الحسابات.

Parameters:

معاملنوعالوصف
imageRasterImageالصورة النقطية.
destBoundsRectangleحدود الصورة الوجهة.
entriesCountintعدد الإدخالات المطلوب.
useImagePalettebooleanإذا تم تعيينه، سيستخدم لوحة ألوان الصورة الخاصة به إذا كانت متوفرة
alphaBlendInColorColorاللون الذي يجب استخدامه كلون خلفية لاستبدال ألفا شبه الشفاف.
keepTransparencybooleanإذا تم تعيينه، سيأخذ في الاعتبار بتات قناة ألفا لألوان الصورة.

Returns: IColorPalette - The color palette which starts with the most frequent colors from the image and contains entriesCount entries.

getUniformColorPalette(RasterImage image)

public static ColorPalette getUniformColorPalette(RasterImage image)

احصل على لوحة ألوان موحدة مكوّنة من 256 لونًا.

Parameters:

معاملنوعالوصف
imageRasterImageالصورة.

Returns: ColorPalette - The ColorPalette.

getDownscalePalette(RasterImage image)

public static ColorPalette getDownscalePalette(RasterImage image)

احصل على لوحة ألوان مكوّنة من 256 لونًا، مكوّنة من البتات العليا لقيم ألوان الصورة الأصلية.

Parameters:

معاملنوعالوصف
imageRasterImageالصورة.

Returns: ColorPalette - The ColorPalette.

hasTransparentColors(IColorPalette palette)

public static boolean hasTransparentColors(IColorPalette palette)

يحدد ما إذا كانت اللوحة المحددة تحتوي على ألوان شفافة.

Parameters:

معاملنوعالوصف
paletteIColorPaletteلوحة الألوان.

Returns: منطقي - true إذا كانت لوحة الألوان المحددة تحتوي على ألوان شفافة؛ وإلا false.

createGrayscale(int bits)

public static IColorPalette createGrayscale(int bits)

يحصل على لوحة الألوان الرمادية لعدد البتات المحدد. قيم البت المسموح بها هي 1، 2، 4، 8.

Parameters:

معاملنوعالوصف
بتاتintعدد البتات.

Returns: IColorPalette - Grayscale palette.