تحسين معالجة الصور باستخدام API الحديث

المقدمة

يعتمد API العام لـ Aspose.Slides for Python حاليًا على الأنواع التالية من aspose.pydrawing:

  • aspose.pydrawing.Graphics
  • aspose.pydrawing.Image
  • aspose.pydrawing.Bitmap
  • aspose.pydrawing.printing.PrinterSettings

اعتبارًا من الإصدار 24.4، تم إهمال هذا API العام بسبب التغييرات في API العام لـ Aspose.Slides for Python.

لإزالة aspose.pydrawing من API العام، قدمنا API الحديث. الطرق التي تستخدم aspose.pydrawing.Image و aspose.pydrawing.Bitmap تم إهمالها وسيتم استبدالها بنظيراتها في API الحديث. الطرق التي تستخدم aspose.pydrawing.Graphics تم إهمالها، وسيتم إزالة الدعم لها من API العام.

من المخطط إزالة API المُهمل الذي يعتمد على aspose.pydrawing في الإصدار 24.8.

API الحديث

تمت إضافة الفئات والعدادات (enums) التالية إلى API العام:

سيناريو الاستخدام النموذجي للـ API الجديد يبدو هكذا:

import aspose.slides as slides
import aspose.pydrawing as drawing

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    with slides.Images.from_file("image.png") as image:
        pp_image = presentation.images.add_image(image)

    slide.shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 10, 10, 100, 100, pp_image)

    with slide.get_image(drawing.Size(1920, 1080)) as slide_image:
        slide_image.save("slide1.jpeg", slides.ImageFormat.JPEG)

استبدال الكود القديم بـ API الحديث

لتسهيل الانتقال، فئة IImage الجديدة تعكس واجهات Image و Bitmap المنفصلة. في معظم الحالات، تحتاج فقط إلى استبدال استدعاءات الطرق التي تستخدم aspose.pydrawing بنظيراتها في API الحديث.

الحصول على صورة مصغرة للشريحة

API المُهمل:

import aspose.slides as slides

with slides.Presentation("sample.pptx") as presentation:
    slide = presentation.slides[0]

    slide.get_thumbnail().save("slide1.png")

API الحديث:

import aspose.slides as slides

with slides.Presentation("sample.pptx") as presentation:
    slide = presentation.slides[0]

    with slide.get_image() as image:
        image.save("slide1.png")

الحصول على صورة مصغرة للشكل

API المُهمل:

import aspose.slides as slides

with slides.Presentation("sample.pptx") as presentation:
    shape = presentation.slides[0].shapes[0]
    
    shape.get_thumbnail().save("shape.png")

API الحديث:

import aspose.slides as slides

with slides.Presentation("sample.pptx") as presentation:
    shape = presentation.slides[0].shapes[0]

    with shape.get_image() as image:
        image.save("shape.png")

الحصول على صورة مصغرة للعرض

API المُهمل:

import aspose.slides as slides
import aspose.pydrawing as drawing

with slides.Presentation("sample.pptx") as presentation:
    thumbnails = presentation.get_thumbnails(slides.export.RenderingOptions(), drawing.Size(1980, 1028))

    for index, thumbnail in enumerate(thumbnails):
        thumbnail.save(f"slide_{index}.png", drawing.imaging.ImageFormat.png)

API الحديث:

import aspose.slides as slides
import aspose.pydrawing as drawing

with slides.Presentation("sample.pptx") as presentation:
    thumbnails = presentation.get_images(slides.export.RenderingOptions(), drawing.Size(1980, 1028))

    for index, thumbnail in enumerate(thumbnails):
        thumbnail.save(f"slide_{index}.png", slides.ImageFormat.PNG)

إضافة صورة إلى عرض تقديمي

API المُهمل:

import aspose.slides as slides
import aspose.pydrawing as drawing

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    image = drawing.Image.from_file("image.png")
    pp_image = presentation.images.add_image(image)
    slide.shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 10, 10, 100, 100, pp_image)

API الحديث:

import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    with slides.Images.from_file("image.png") as image:
        pp_image = presentation.images.add_image(image)

    slide.shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 10, 10, 100, 100, pp_image)

الطرق والخصائص التي ستُحذف وتبديلاتها الحديثة

فئة Presentation

توقيع الطريقة توقيع طريقة الاستبدال
get_thumbnails(options) get_images(options)
get_thumbnails(options, slides) get_images(options, slides)
get_thumbnails(options, scale_x, scale_y) get_images(options, scale_x, scale_y)
get_thumbnails(options, slides, scale_x, scale_y) get_images(options, slides, scale_x, scale_y)
get_thumbnails(options, image_size) get_images(options, image_size)
get_thumbnails(options, slides, image_size) get_images(options, slides, image_size)
save(fname, format, response, show_inline) Will be deleted completely
save(fname, format, options, response, show_inline) Will be deleted completely
print() Will be deleted completely
print(printer_settings) Will be deleted completely
print(printer_name) Will be deleted completely
print(printer_settings, pres_name) Will be deleted completely

فئة Slide

توقيع الطريقة توقيع طريقة الاستبدال
get_thumbnail() get_image()
get_thumbnail(scale_x, scale_y) get_image(scale_x, scale_y)
get_thumbnail(image_size) get_image(image_size)
get_thumbnail(options) get_image(options: ITiffOotions)
get_thumbnail(options) get_image(options: IRenderingOptions)
get_thumbnail(options, scale_x, scale_y) get_image(options, scale_x, scale_y)
get_thumbnail(options, image_size) get_image(options, image_size)
render_to_graphics(options, graphics) Will be deleted completely
render_to_graphics(options, graphics, scale_x, scale_y) Will be deleted completely
render_to_graphics(options, graphics, rendering_size) Will be deleted completely

فئة Shape

توقيع الطريقة توقيع طريقة الاستبدال
get_thumbnail() get_image()
get_thumbnail(bounds, scale_x, scale_y) get_image(bounds, scale_x, scale_y)

فئة ImageCollection

توقيع الطريقة توقيع طريقة الاستبدال
add_image(image: aspose.pydrawing.Image) add_image(image)

فئة PPImage

توقيع الطريقة/الخاصية توقيع طريقة/خاصية الاستبدال
replace_image(new_image: aspose.pydrawing.Image) replace_image(new_image)
system_image image

فئة ImageWrapperFactory

توقيع الطريقة توقيع طريقة الاستبدال
create_image_wrapper(image: aspose.pydrawing.Image) create_image_wrapper(image)

فئة PatternFormat

توقيع الطريقة توقيع طريقة الاستبدال
get_tile_image(background, foreground) get_tile(background, foreground)
get_tile_image(style_color) get_tile(style_color)

فئة IPatternFormatEffectiveData

توقيع الطريقة توقيع طريقة الاستبدال
get_tile_image(background, foreground) get_tile_i_image(background, foreground)

فئة Output

توقيع الطريقة توقيع طريقة الاستبدال
add(path, image: aspose.pydrawing.Image) add(path, image)

ستتوقف دعم aspose.pydrawing.Graphics في API

الطرق التي تستخدم aspose.pydrawing.Graphics تم إهمالها؛ سيتم إزالة الدعم لها من API العام.

الأعضاء الذين يعتمدون على aspose.pydrawing.Graphics وسيتم إزالتهم هم:

  • aspose.pydrawing.Slide.render_to_graphics(options, graphics)
  • aspose.pydrawing.Slide.render_to_graphics(options, graphics, scale_x, scale_y)
  • aspose.pydrawing.Slide.render_to_graphics(options, graphics, rendering_size)

FAQ

لماذا تم إلغاء aspose.pydrawing.Graphics؟

يتم إزالة الدعم لـ Graphics من API العام لتوحيد العمل مع التصيير والصور، وإلغاء الارتباط بالاعتمادات الخاصة بالمنصات، والتحول إلى نهج متعدد المنصات باستخدام IImage. سيتم إلغاء جميع طرق التصيير إلى Graphics.

ما الفائدة العملية من IImage مقارنةً بـ Image/Bitmap؟

IImage يوحّد التعامل مع الصور النقطية والمتجهة، يبسط الحفظ إلى صيغ مختلفة عبر ImageFormat، يقلل الاعتماد على pydrawing، ويجعل الشيفرة أكثر قابلية للنقل بين البيئات.

هل سيؤثر API الحديث على أداء توليد الصور المصغرة؟

التحول من get_thumbnail إلى get_image لا يُضعف السيناريوهات: الطرق الجديدة توفر نفس القدرات لإنتاج الصور مع الخيارات والأحجام، مع الحفاظ على دعم خيارات التصيير. الفائدة أو الخسارة المحددة تعتمد على السيناريو، لكن وظيفيًا البدائل متكافئة.