فئة ImageOptionsBase
Summary: The image base options.
Module: aspose.imaging
Full Name: aspose.imaging.ImageOptionsBase
Inheritance: IMetadataContainer, IHasExifData, IHasMetadata, IHasXmpData, DisposableObject
Properties
| Name | Type | Access | الوصف |
|---|---|---|---|
| buffer_size_hint | int | r/w | يحصل أو يعيّن تلميح حجم المخزن المؤقت الذي يُعرف كأقصى حجم مسموح به لجميع المخازن الداخلية. |
| تم التخلص | bool | r | يحصل على قيمة تشير إلى ما إذا كانت هذه المثيلة تم التخلص منها. |
| exif_data | ExifData | r/w | يحصل أو يعيّن بيانات Exif. |
| full_frame | bool | r/w | يحصل أو يعيّن قيمة تشير إلى ما إذا كان [full frame]. |
| keep_metadata | bool | r/w | يحصل على قيمة ما إذا كان يجب الاحتفاظ ببيانات التعريف الأصلية للصورة عند التصدير. |
| multi_page_options | MultiPageOptions | r/w | خيارات الصفحات المتعددة |
| palette | IColorPalette | r/w | يحصل أو يضبط لوحة الألوان. |
| resolution_settings | ResolutionSetting | r/w | يحصل أو يضبط إعدادات الدقة. |
| source | Source | r/w | يحصل أو يضبط المصدر لإنشاء الصورة فيه. |
| vector_rasterization_options | VectorRasterizationOptions | r/w | يحصل أو يضبط خيارات تحويل المتجه إلى نقطية. |
| xmp_data | XmpPacketWrapper | r/w | يحصل أو يضبط حاوية بيانات التعريف XMP. |
Methods
| Name | الوصف |
|---|---|
| clone() | ينشئ نسخة متماثلة لهذا الكائن. |
| try_set_metadata(metadata) | يحاول ضبط مثال metadata، إذا كان مثال هذا Image يدعم ويطبق مثال IImageMetadataFormat . |
Property: buffer_size_hint
يحصل أو يعيّن تلميح حجم المخزن المؤقت الذي يُعرف كأقصى حجم مسموح به لجميع المخازن الداخلية.
See also:
Example # 1: The following example shows how to set a memory limit when creating a new JPE…
Property: palette
يحصل أو يضبط لوحة الألوان.
See also:
Example # 1: The following example shows how to set a palette to a BMP image to reduce its…
Example # 2: The following example shows how to compress a PNG image, using indexed color …
Example # 3: The following example loads a BMP image and saves it back to BMP using variou…
Property: resolution_settings
يحصل أو يضبط إعدادات الدقة.
See also:
Example # 1: The following example loads a BMP image and saves it back to BMP using variou…
Example # 2: The following example creates a palettized grayscale BMP image and then saves…
Method: clone()
clone()
ينشئ نسخة متماثلة لهذا الكائن.
Returns
| نوع | الوصف |
|---|---|
| ImageOptionsBase | نسخة متماثلة لهذا الكائن. |
Method: try_set_metadata(metadata)
try_set_metadata(metadata)
يحاول ضبط مثال metadata، إذا كان مثال هذا Image يدعم ويطبق مثال IImageMetadataFormat .
Parameters:
| معامل | نوع | الوصف |
|---|---|---|
| metadata | IImageMetadataFormat | البيانات الوصفية. |
Returns
| نوع | الوصف |
|---|---|
| bool | صحيح، إذا كان كائن IMetadataContainer يدعم و/أو ينفّذ كائن IImageMetadataFormat; وإلا، خطأ. |
Examples
The following example shows how to set a palette to a BMP image to reduce its output size.
from aspose.pycore import as_of
from aspose.imaging import Point, Color, Graphics, ColorPaletteHelper
from aspose.imaging.brushes import LinearGradientBrush
from aspose.imaging.fileformats.bmp import BmpImage
from aspose.imaging.imageoptions import BmpOptions
from os.path import join as path_join
# إنشاء صورة BMP بحجم 100 × 100 بكسل.
with BmpImage(100, 100) as bmpImage:
# التدرج الخطي من الزاوية اليسرى العليا إلى الزاوية اليمنى السفلى للصورة.
brush = LinearGradientBrush(Point(0, 0), Point(bmpImage.width, bmpImage.height),
Color.red,
Color.green)
# املأ الصورة بالكامل بفرشاة التدرج الخطي.
gr = Graphics(bmpImage)
gr.fill_rectangle(brush, bmpImage.bounds)
# احصل على أقرب لوحة ألوان 8‑بت تغطي أكبر عدد ممكن من البكسلات، بحيث تكون الصورة الملونة باللوحة
# تقريبًا لا يمكن تمييزها بصريًا عن صورة BMP بدون لوحة ألوان
palette = ColorPaletteHelper.get_close_image_palette(bmpImage, 256)
# لوحة ألوان 8‑بت تحتوي على حد أقصى 256 لونًا.
saveOptions = BmpOptions()
saveOptions.palette = palette
saveOptions.bits_per_pixel = 8
with stream_ext.create_memory_stream() as stream:
bmpImage.save(stream, saveOptions)
print(f"The size of image with palette is {stream.tell()} bytes.")
stream.seek(0)
bmpImage.save(stream)
print(f"The size of image without palette is {stream.tell()} bytes.")
# المخرجات تبدو هكذا:
# حجم الصورة مع اللوحة هو 11078 بايت.
# حجم الصورة بدون لوحة هو 40054 بايت.
The following example shows how to compress a PNG image, using indexed color with best fit palette
from aspose.pycore import as_of
from aspose.imaging import Image, ColorPaletteHelper, RasterImage, PaletteMiningMethod
from aspose.imaging.fileformats.png import PngColorType
# يحمّل صورة PNG
sourceFilePath = "OriginalRings.png"
outputFilePath = "OriginalRingsOutput.png"
with Image.load(sourceFilePath) as image:
png_options = PngOptions()
png_options.progressive = True
# استخدم نوع اللون المفهرس
png_options.color_type = PngColorType.INDEXED_COLOR
# استخدم أقصى ضغط
png_options.compression_level = 9
# احصل على أقرب لوحة ألوان 8‑بت، تغطي أكبر عدد ممكن من البكسلات، بحيث تكون الصورة
# مع لوحة ألوان تقريبًا لا يمكن تمييزها بصريًا عن صورة بدون لوحة ألوان.
png_options.palette = ColorPaletteHelper.get_close_image_palette(
as_of(image, RasterImage), 256,
PaletteMiningMethod.HISTOGRAM)
image.save(outputFilePath, png_options);
}
# يجب تقليل حجم ملف الإخراج بشكل كبير
The following example loads a BMP image and saves it back to BMP using various save options.
from aspose.imaging import Image, RasterImage, ColorPaletteHelper, ResolutionSetting
from aspose.imaging.imageoptions import BmpOptions
from aspose.imaging.fileformats.bmp import BitmapCompression
import os
import aspose.pycore as aspycore
directory = "c:\\temp\\"
with Image.load(os.path.join(directory, "sample.bmp")) as image:
rasterImage = aspycore.as_of(image, RasterImage)
# إنشاء BmpOptions
saveOptions = BmpOptions()
# استخدم 8 بتات لكل بكسل لتقليل حجم الصورة الناتجة.
saveOptions.bits_per_pixel = 8
# عيّن أقرب لوحة ألوان 8‑بت تغطي الحد الأقصى لعدد بكسلات الصورة، بحيث تكون الصورة الملونة باللوحة
# يكاد يكون غير قابل للتمييز بصريًا عن نسخة غير مُلوَّنة.
saveOptions.palette = ColorPaletteHelper.get_close_image_palette(rasterImage, 256)
# احفظ دون ضغط.
# يمكنك أيضًا استخدام ضغط RLE-8 لتقليل حجم الصورة الناتجة.
saveOptions.compression = BitmapCompression.RGB
# عيّن الدقة الأفقية والعمودية إلى 96 نقطة في البوصة.
saveOptions.resolution_settings = ResolutionSetting(96.0, 96.0)
image.save(os.path.join(directory, "sample.bmpoptions.bmp"), saveOptions)
The following example creates a palettized grayscale BMP image and then saves it to a file.
from os.path import join as path_join
from aspose.imaging import Image, ColorPaletteHelper, ResolutionSetting, Graphics, Point, Color
from aspose.imaging.sources import FileCreateSource
from aspose.imaging.imageoptions import BmpOptions
from aspose.imaging.fileformats.bmp import BitmapCompression
from aspose.imaging.brushes import LinearGradientBrush
directory = "c:\\temp\\"
createOptions = BmpOptions()
# احفظ إلى ملف
createOptions.source = FileCreateSource(path_join(directory, "output.palette8bit.bmp"), False)
# استخدم 8 بتات لكل بكسل لتقليل حجم الصورة الناتجة.
createOptions.bits_per_pixel = 8
# عيّن لوحة ألوان التدرج الرمادي القياسية 8‑بت التي تغطي جميع ألوان التدرج الرمادي.
# إذا كانت الصورة المعالجة تحتوي فقط على ألوان التدرج الرمادي، فإن نسختها الملوَّنة
# غير قابلة للتمييز بصريًا عن نسخة غير ملوَّنة.
createOptions.palette = ColorPaletteHelper.create_8_bit_grayscale(False)
# احفظ دون ضغط.
# يمكنك أيضًا استخدام ضغط RLE-8 لتقليل حجم الصورة الناتجة.
createOptions.compression = BitmapCompression.RGB
# عيّن الدقة الأفقية والعمودية إلى 96 نقطة في البوصة.
createOptions.resolution_settings = ResolutionSetting(96.0, 96.0)
# أنشئ صورة BMP بحجم 100 × 100 بكسل واحفظها إلى ملف.
with Image.create(createOptions, 100, 100) as image:
graphics = Graphics(image)
gradientBrush = LinearGradientBrush(Point(0, 0), Point(image.width, image.height), Color.black, Color.white)
# املأ الصورة بتدرج رمادي
graphics.fill_rectangle(gradientBrush, image.bounds)
image.save()
The following example shows how to set a memory limit when creating a new JPEG image. The memory limit is the maximum allowed size (in megabytes) for all internal buffers.
from os.path import join
from aspose.imaging import Image
from aspose.imaging.sources import FileCreateSource
from aspose.imaging.imageoptions import JpegOptions
from aspose.imaging.fileformats.jpeg import JpegCompressionMode
dir_: str = "c:\\aspose.imaging\\issues\\net\\3404\\"
# تعيين حد الذاكرة إلى 50 ميغابايت للصورة المستهدفة المُنشأة
create_options = JpegOptions()
create_options.compression_type = JpegCompressionMode.PROGRESSIVE
create_options.buffer_size_hint = 50
create_options.source = FileCreateSource(join(dir_, "createdFile.jpg"), False)
with Aspose.Imaging.Image.create(create_options, 1000, 1000) as image:
# احفظ إلى نفس الموقع
image.save()