فئة PngOptions

Summary: Create high-quality Portable Network Graphics (PNG) raster images effortlessly
with our API, offering customizable options for compression levels,
bits per pixel depths, and alpha bits. Seamlessly process XMP metadata containers,
ensuring comprehensive image metadata management, and empowering you to tailor
PNG images to your exact specifications with ease.

Module: aspose.imaging.imageoptions

Full Name: aspose.imaging.imageoptions.PngOptions

Inheritance: IMetadataContainer, IHasExifData, IHasMetadata, IHasXmpData, ImageOptionsBase

Constructors

Nameالوصف
PngOptions()يقوم بإنشاء نسخة جديدة من الفئة PngOptions.
PngOptions(png_options)يقوم بإنشاء نسخة جديدة من الفئة PngOptions.

Properties

NameTypeAccessالوصف
DEFAULT_COMPRESSION_LEVEL [static]PngCompressionLevelrمستوى الضغط الافتراضي.
bit_depthSystem.Byter/wيحصل أو يعيّن قيم عمق البت في النطاق 1، 2، 4، 8، 16.


انتبه إلى الحدود التالية:


PngColorType.INDEXED_COLOR يدعم عمق البت 1، 2، 4، 8.


PngColorType.GRAYSCALE, PngColorType.GRAYSCALE_WITH_ALPHA يدعمان عمق البت 8.


PngColorType.TRUECOLOR, PngColorType.TRUECOLOR_WITH_ALPHA يدعمان عمق البت 8، 16.

buffer_size_hintintr/wيحصل أو يعيّن تلميح حجم المخزن المؤقت الذي يُعرف كأقصى حجم مسموح به لجميع المخازن الداخلية.
color_typePngColorTyper/wيحصل أو يعيّن نوع اللون.
compression_levelintr/wيحصل أو يعيّن مستوى ضغط PngImage.
تم التخلصboolrيحصل على قيمة تشير إلى ما إذا كانت هذه المثيلة تم التخلص منها.
exif_dataExifDatar/wيحصل أو يعيّن بيانات Exif.
filter_typePngFilterTyper/wيحصل أو يعيّن نوع الفلتر المستخدم أثناء عملية حفظ ملف png.
full_frameboolr/wيحصل أو يعيّن قيمة تشير إلى ما إذا كان [full frame].
keep_metadataboolr/wيحصل على قيمة ما إذا كان يجب الاحتفاظ ببيانات التعريف الأصلية للصورة عند التصدير.
multi_page_optionsMultiPageOptionsr/wخيارات الصفحات المتعددة
paletteIColorPaletter/wيحصل أو يضبط لوحة الألوان.
png_compression_levelPngCompressionLevelr/wيحصل أو يعيّن مستوى ضغط PngImage.
progressiveboolr/wيحصل أو يعيّن قيمة تشير إلى ما إذا كان PngImage تقدميًا.
resolution_settingsResolutionSettingr/wيحصل أو يضبط إعدادات الدقة.
sourceSourcer/wيحصل أو يضبط المصدر لإنشاء الصورة فيه.
vector_rasterization_optionsVectorRasterizationOptionsr/wيحصل أو يضبط خيارات تحويل المتجه إلى نقطية.
xmp_dataXmpPacketWrapperr/wيحصل أو يضبط حاوية بيانات التعريف XMP.

Methods

Nameالوصف
clone()ينشئ نسخة متماثلة لهذا الكائن.
try_set_metadata(metadata)يحاول ضبط مثال metadata، إذا كان مثال هذا Image يدعم ويطبق مثال IImageMetadataFormat .

Constructor: PngOptions()

 PngOptions() 

يقوم بإنشاء نسخة جديدة من الفئة PngOptions.

Constructor: PngOptions(png_options)

 PngOptions(png_options) 

يقوم بإنشاء نسخة جديدة من الفئة PngOptions.

Parameters:

معاملنوعالوصف
png_optionsPngOptionsخيارات PNG.

Property: color_type

يحصل أو يعيّن نوع اللون.

See also:

Example # 1: The following example shows how to compress a PNG image, using indexed color …

Property: compression_level

يحصل أو يعيّن مستوى ضغط PngImage.

See also:

Example # 1: The following example shows how to compress a PNG image, using indexed color …

Property: progressive

يحصل أو يعيّن قيمة تشير إلى ما إذا كان PngImage تقدميًا.

See also:

Example # 1: The following example shows how to compress a PNG image, using indexed color …

Method: clone()

 clone() 

ينشئ نسخة متماثلة لهذا الكائن.

Returns

نوعالوصف
ImageOptionsBaseنسخة متماثلة لهذا الكائن.

Method: try_set_metadata(metadata)

 try_set_metadata(metadata) 

يحاول ضبط مثال metadata، إذا كان مثال هذا Image يدعم ويطبق مثال IImageMetadataFormat .

Parameters:

معاملنوعالوصف
metadataIImageMetadataFormatالبيانات الوصفية.

Returns

نوعالوصف
boolصحيح، إذا كان كائن IMetadataContainer يدعم و/أو ينفّذ كائن IImageMetadataFormat; وإلا، خطأ.

Examples

This example uses Graphics class to create primitive shapes on the Image surface. To demonstrate the operation, the example creates a new Image in PNG format and draw primitive shapes on Image surface using Draw methods exposed by Graphics class


from aspose.imaging import Image, RotateFlipType, Graphics, Color, Pen, Rectangle, Point, Size,\
	Font, PointF
from aspose.imaging.brushes import SolidBrush
from aspose.imaging.imageoptions import PngOptions
from aspose.imaging.fileformats.psd import CompressionMethod, ColorModes
from aspose.imaging.sources import StreamSource

from os.path import join as path_join

#ينشئ مثيلاً من تدفق الملف.
with open(r"C:\temp\output.png", "w+b") as stream:
	#إنشاء مثيل من PngOptions وتعيين خصائصه المتنوعة.
	pngOptions = PngOptions()
	#تعيين المصدر لـ PngOptions.
	pngOptions.source = StreamSource(stream)
	#إنشاء مثيل من Image.
	with Image.create(pngOptions, 500, 500) as image:
		#إنشاء وتهيئة مثيل من فئة Graphics.
		graphics = Graphics(image)
		#مسح سطح Graphics.
		graphics.clear(Color.wheat);
		#ارسم قوسًا بتحديد كائن Pen الذي لديه لون أسود،
		#مستطيل يحيط بالقوس، زاوية البداية وزاوية المسح
		graphics.draw_arc(Pen(Color.black, 2.0), Rectangle(200, 200, 100, 200), 0, 300)
		#ارسم منحنى Bezier بتحديد كائن Pen الذي لديه لون أزرق ونقاط الإحداثيات.
		graphics.draw_bezier(Pen(Color.blue, 2.0), Point(250, 100), Point(300, 30), Point(450, 100), Point(235, 25))
		#ارسم منحنى عن طريق تحديد كائن Pen ذو اللون الأخضر ومصفوفة من Points
		graphics.draw_curve(Pen(Color.green, 2.0), [Point(100, 200), Point(100, 350), Point(200, 450)])
		#ارسم إهليلجًا باستخدام كائن Pen ومستطيل محيط
		graphics.draw_ellipse(Pen(Color.yellow, 2.0), Rectangle(300, 300, 100, 100))
		#ارسم خطًا
		graphics.draw_line(Pen(Color.violet, 2.0), Point(100, 100), Point(200, 200))
		#ارسم قطعة فطيرة
		graphics.draw_pie(Pen(Color.silver, 2.0), Rectangle(Point(200, 20), Size(200, 200)), 0, 45);
		#ارسم مضلعًا بتحديد كائن Pen ذو اللون الأحمر ومصفوفة من Points
		graphics.draw_polygon(Pen(Color.red, 2.0), [Point(20, 100), Point(20, 200), Point(220, 20)])
		#ارسم مستطيلًا
		graphics.draw_rectangle(Pen(Color.orange, 2.0), Rectangle(Point(250, 250), Size(100, 100)))
		#أنشئ كائن SolidBrush واضبط خصائصه المتنوعة
		brush = SolidBrush()
		brush.color = Color.purple
		#ارسم نصًا باستخدام كائن SolidBrush و Font، عند نقطة محددة
		graphics.draw_string("This image is created by Aspose.Imaging API", Font("Times New Roman", 16),
							 brush, PointF(50.0, 400.0))
		# احفظ جميع التغييرات.
		image.save();

This example demonstrates the use of different classes from imageoptions package for export purposes. A gif image is loaded as an instance of Image and then exported out to several formats.


from aspose.imaging import Image
from aspose.imaging.imageoptions import BmpOptions, JpegOptions, PngOptions, TiffOptions
from aspose.imaging.fileformats.tiff.enums import TiffExpectedFormat
from os.path import join as path_join

directory = "c:\\temp\\"
#تحميل صورة gif موجودة كمثيل لفئة Image
with Image.load(path_join(directory, "sample.gif")) as image:
	# تصدير إلى تنسيق ملف BMP باستخدام الخيارات الافتراضية
	image.save(path_join(directory, "output.bmp"), BmpOptions())
	# تصدير إلى تنسيق ملف JPEG باستخدام الخيارات الافتراضية
	image.save(path_join(directory, "output.jpg"), JpegOptions())
	# تصدير إلى تنسيق ملف PNG باستخدام الخيارات الافتراضية
	image.save(path_join(directory, "output.png"), PngOptions())
	# تصدير إلى تنسيق ملف TIFF باستخدام الخيارات الافتراضية
	image.save(path_join(directory, "output.tif"), TiffOptions(TiffExpectedFormat.DEFAULT))

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);
}
# يجب تقليل حجم ملف الإخراج بشكل كبير