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

مقدمة

حالياً، مكتبة Aspose.Slides للغة C++ تحتوي على تبعيات في واجهة برمجة التطبيقات العامة على الفئات التالية من System::Drawing:

اعتبارًا من الإصدار 24.4، تم إعلان أن واجهة برمجة التطبيقات العامة هذه مهجورة.

من أجل التخلص من التبعيات على System::Drawing في واجهة برمجة التطبيقات العامة، أضفنا ما يُسمى بـ “Modern API”. تُعلن الطرق التي تستخدم System::Drawing::Image و System::Drawing::Bitmap كمهجورة ويجب استبدالها بالطرق المقابلة من Modern API. تُعلن الطرق التي تستخدم System::Drawing::Graphics كمهجورة ولا يوجد بديل مباشر في Modern API.

في الإصدارات الحالية، اعتبر واجهة برمجة التطبيقات العامة التي تعتمد على أنواع System::Drawing كقديمة/مهجورة. استخدم Modern API للشفرة الجديدة وعند ترحيل تدفقات عمل معالجة الصور الحالية.

API الحديثة

تمت إضافة الفئات والعدادات التالية إلى واجهة برمجة التطبيقات العامة:

استخدم GetImage لتصوير شريحة واحدة أو شكل. استخدم GetImages لتصوير عدة شرائح عرض. استخدم طرق Images لتحميل الصور، AddImage مع IImage لإضافتها إلى عرض تقديمي، و ReplaceImage مع IImage لتحديث صورة عرض تقديمي موجودة.

قد يبدو سيناريو الاستخدام النموذجي للـ API الجديد على النحو التالي:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
        
// إنشاء نسخة قابلة للتصرف من IImage من الملف على القرص.  
System::SharedPtr<IImage> image = Images::FromFile(u"image.png");
            
// إنشاء صورة PowerPoint بإضافة نسخة من IImage إلى صور العرض التقديمي.
System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);
        
// إضافة شكل صورة على الشريحة #1
pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);
        
// الحصول على نسخة من IImage تمثل الشريحة #1.
auto slideImage = pres->get_Slide(0)->GetImage(System::Drawing::Size(1920, 1080));

// حفظ الصورة على القرص.
slideImage->Save(u"slide1.jpeg", Aspose::Slides::ImageFormat::Jpeg);

استبدال الشيفرة القديمة بـ API الحديثة

لتسهيل الانتقال، يكرر واجهة IImage التواقيع المنفصلة لفئات System::Drawing::Image و System::Drawing::Bitmap. بشكل عام، ستحتاج فقط إلى استبدال استدعاء الطريقة القديمة التي تستخدم System::Drawing بالواحدة الجديدة.

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

واجهة برمجة التطبيقات القديمة/المهجورة:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

pres->get_Slide(0)->GetThumbnail()->Save(u"slide1.png");

API الحديثة:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

pres->get_Slide(0)->GetImage()->Save(u"slide1.png");

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

واجهة برمجة التطبيقات القديمة/المهجورة:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

pres->get_Slide(0)->get_Shape(0)->GetThumbnail()->Save(u"shape.png");

API الحديثة:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

pres->get_Slide(0)->get_Shape(0)->GetImage()->Save(u"shape.png");

الحصول على صورة مصغرة للعرض التقديمي

واجهة برمجة التطبيقات القديمة/المهجورة:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

auto bitmaps = pres->GetThumbnails(System::MakeObject<RenderingOptions>(), System::Drawing::Size(1980, 1028));

for (int32_t index = 0; index < bitmaps->get_Length(); index++)
{
    System::SharedPtr<System::Drawing::Bitmap> thumbnail = bitmaps[index];
    thumbnail->Save(System::String::Format(u"slide_{0}.png", index), System::Drawing::Imaging::ImageFormat::get_Png());
}

API الحديثة:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

auto images = pres->GetImages(System::MakeObject<RenderingOptions>(), System::Drawing::Size(1980, 1028));

for (int32_t index = 0; index < images->get_Length(); index++)
{
    System::SharedPtr<IImage> thumbnail = images[index];
    thumbnail->Save(System::String::Format(u"slide_{0}.png", index), Aspose::Slides::ImageFormat::Png);
}

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

واجهة برمجة التطبيقات القديمة/المهجورة:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();

System::SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(u"image.png");

System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);

pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);

API الحديثة:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();

System::SharedPtr<Aspose::Slides::IImage> image = Aspose::Slides::Images::FromFile(u"image.png");

System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);

pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);

الطرق/الخصائص المهجورة واستبدالاتها في API الحديثة

فئة Presentation

توقيع الطريقة توقيع طريقة الاستبدال
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options) GetImages(System::SharedPtr<Export::IRenderingOptions> options)
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides) GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides)
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) GetImages(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY)
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, float scaleX, float scaleY) GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, float scaleX, float scaleY)
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize)
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, System::Drawing::Size imageSize) GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, System::Drawing::Size imageSize)
Save(System::String fname, System::ArrayPtr<int32_t> slides, Export::SaveFormat format) No Modern API replacement
Save(System::String fname, System::ArrayPtr<int32_t> slides, Export::SaveFormat format, System::SharedPtr<Export::ISaveOptions> options) No Modern API replacement

فئة Slide

توقيع الطريقة توقيع طريقة الاستبدال
GetThumbnail() GetImage()
GetThumbnail(float scaleX, float scaleY) GetImage(float scaleX, float scaleY)
GetThumbnail(System::Drawing::Size imageSize) GetImage(System::Drawing::Size imageSize)
GetThumbnail(System::SharedPtr<Export::ITiffOptions> options) GetImage(System::SharedPtr<Export::IRenderingOptions> options
GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options) GetImage(System::SharedPtr<Export::IRenderingOptions> options)
GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) GetImage(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY)
GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) GetImage(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize)
RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics) No Modern API replacement
RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics, float scaleX, float scaleY) No Modern API replacement
RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics, System::Drawing::Size renderingSize) No Modern API replacement

فئة Shape

توقيع الطريقة توقيع طريقة الاستبدال
GetThumbnail() GetImage()
GetThumbnail(ShapeThumbnailBounds bounds, float scaleX, float scaleY) GetImage(ShapeThumbnailBounds bounds, float scaleX, float scaleY)

فئة ImageCollection

توقيع الطريقة توقيع طريقة الاستبدال
AddImage(System::SharedPtr<System::Drawing::Image> image) AddImage(System::SharedPtr<IImage> image)

فئة PPImage

توقيع الطريقة توقيع طريقة الاستبدال
ReplaceImage(System::SharedPtr<System::Drawing::Image> newImage) ReplaceImage(System::SharedPtr<Aspose::Slides::IImage> newImage)
get_SystemImage() get_Image()

فئة PatternFormat

توقيع الطريقة توقيع طريقة الاستبدال
GetTileImage(System::Drawing::Color background, System::Drawing::Color foreground) GetTile(System::Drawing::Color background, System::Drawing::Color foreground)
GetTileImage(System::Drawing::Color styleColor) GetTile(System::Drawing::Color styleColor)

فئة IPatternFormatEffectiveData

توقيع الطريقة توقيع طريقة الاستبدال
GetTileImage(System::Drawing::Color background, System::Drawing::Color foreground) GetTileIImage(System::Drawing::Color background, System::Drawing::Color foreground)

دعم API لـ System::Drawing::Graphics

تُعلن الطرق التي تستخدم System::Drawing::Graphics كمهجورة ولا يوجد لها بديل مباشر في Modern API.

استخدم طرق عرض الصور في Modern API بدلًا من API التي تُظهر إلى System::Drawing::Graphics:

الأسئلة الشائعة

لماذا تم حذف System::Drawing::Graphics?

تم إهمال دعم System::Drawing::Graphics في واجهة برمجة التطبيقات العامة لتوحيد العمل مع العرض والصور، وإزالة الارتباط بالاعتماديات الخاصة بالمنصة، والانتقال إلى نهج متعدد المنصات باستخدام IImage. استخدم GetImage أو GetImages بدلاً من العرض إلى System::Drawing::Graphics.

ما الفائدة العملية من IImage مقارنةً بـ System::Drawing::Image/System::Drawing::Bitmap?

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

هل سيؤثر Modern API على أداء إنشاء الصور المصغرة؟

الانتقال من GetThumbnail إلى GetImage لا يؤدي إلى تدهور الأداء: الطرق الجديدة توفر نفس الإمكانيات لإنشاء الصور مع الخيارات والأحجام، مع الحفاظ على دعم خيارات العرض. الكسب أو الفقد المحدد يعتمد على السيناريو، لكن من الناحية الوظيفية البدائل متكافئة.