Aspose.Slides لـ Xamarin

نظرة عامة

Xamarin هو إطار يستخدم لتطوير التطبيقات المحمولة في .NET C#. يحتوي Xamarin على أدوات ومكتبات تُوسِّع قدرات منصة .NET. يسمح للمطورين بإنشاء تطبيقات لنظام التشغيل Android.

يعمل Aspose.Slides API على منصة Xamarin. لتحقيق ذلك، يُضيف حزمة Aspose.Slides .NET ملف DLL منفصل لـ Xamarin. يدعم Aspose.Slides لـ Xamarin معظم الميزات المتوفرة في نسخة .NET:

  • تحويل وعرض العروض التقديمية.
  • تحرير محتويات العروض التقديمية: النصوص، الأشكال، المخططات، SmartArt، الصوت/الفيديو، الخطوط، إلخ.
  • معالجة/التعامل مع الرسوم المتحركة، تأثيرات 2D، WordArt، إلخ.
  • معالجة/التعامل مع البيانات التعريفية وخصائص المستند.
  • الطباعة، الاستنساخ، الدمج، المقارنة، التقسيم، إلخ.

لقد قدمنا مقارنة لكامل الميزات في قسم آخر قريب من أسفل هذه الصفحة.

في Aspose.Slides لـ Xamarin API، تكون الفئات والمساحات الاسمية والمنطق والسلوك مشابهة قدر الإمكان لنسخة .NET. يمكنك ترحيل تطبيقات Aspose.Slides .NET إلى Xamarin بأقل التكاليف.

مثال سريع

يمكنك استخدام Aspose.Slides لـ Xamarin لإنشاء واستخدام تطبيق C# الخاص بك عبر Slides for Android.

نقدم مثالاً لتطبيق Android عبر Xamarin يستخدم Aspose.Slides لعرض شرائح العروض التقديمية ويضيف شكلًا جديدًا على الشريحة عند اللمس. يمكنك العثور على المصدر الكامل للأمثلة على GitHub.

لنبدأ بإنشاء تطبيق Xamarin Android:

todo:image_alt_text

أولاً، نقوم بإنشاء تخطيط محتوى يحتوي على عرض صورة، وزر Prev، وزر Next:

todo:image_alt_text

XML - content_main.xml - إنشاء تخطيط المحتوى

 <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation=    "vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:showIn="@layout/activity_main">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:id="@+id/linearLayout1">
        <ImageView
            android:src="@android:drawable/ic_menu_gallery"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView"
            android:scaleType="fitCenter" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="10"
        android:id="@+id/linearLayout2">
        <Button
            android:text="Prev"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/buttonPrev" />
        <Button
            android:text="Next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/buttonNext"/>
    </LinearLayout>
</LinearLayout>

هنا، نُشير إلى مكتبة “Aspose.Slides.Droid.dll” التي تتضمن عرضًا تقديميًا تجريبيًا (“HelloWorld.pptx”) داخل أصول تطبيق Xamarin وتضيف تهيئتها إلى MainActivity:

C# - MainActivity.cs - التهيئة

[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
    private Aspose.Slides.Presentation presentation;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.activity_main);
    }

    protected override void OnResume()
    {
        if (presentation == null)
        {
            using (Stream input = Assets.Open("HelloWorld.pptx"))
            {
                presentation = new Aspose.Slides.Presentation(input);
            }
        }
    }

    protected override void OnPause()
    {
        if (presentation != null)
        {
            presentation.Dispose();
            presentation = null;
        }
    }
}

لنضيف الدالة لعرض شرائح Prev و Next عند النقر على الأزرار:

C# - MainActivity.cs - عرض الشرائح عند النقر على زر Prev و Next

[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
    private Button buttonNext;
    private Button buttonPrev;
    ImageView imageView;

    private Aspose.Slides.Presentation presentation;

    private int currentSlideNumber;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.activity_main);
    }

    protected override void OnResume()
    {
        base.OnResume();
        LoadPresentation();
        currentSlideNumber = 0;
        if (buttonNext == null)
        {
            buttonNext = FindViewById<Button>(Resource.Id.buttonNext);
        }

        if (buttonPrev == null)
        {
            buttonPrev = FindViewById<Button>(Resource.Id.buttonPrev);
        }

        if(imageView == null)
        {
            imageView= FindViewById<ImageView>(Resource.Id.imageView);
        }

        buttonNext.Click += ButtonNext_Click;
        buttonPrev.Click += ButtonPrev_Click;
        RefreshButtonsStatus();
        ShowSlide(currentSlideNumber);
    }

    private void ButtonNext_Click(object sender, System.EventArgs e)
    {
        if (currentSlideNumber > (presentation.Slides.Count - 1))
        {
            return;
        }

        ShowSlide(++currentSlideNumber);
        RefreshButtonsStatus();
    }

    private void ButtonPrev_Click(object sender, System.EventArgs e)
    {
        if (currentSlideNumber == 0)
        {
            return;
        }

        ShowSlide(--currentSlideNumber);
        RefreshButtonsStatus();
    }

    protected override void OnPause()
    {
        base.OnPause();
        if (buttonNext != null)
        {
            buttonNext.Dispose();
            buttonNext = null;
        }

        if (buttonPrev != null)
        {
            buttonPrev.Dispose();
            buttonPrev = null;
        }

        if(imageView != null)
        {
            imageView.Dispose();
            imageView = null;
        }

        DisposePresentation();
    }

    private void RefreshButtonsStatus()
    {
        buttonNext.Enabled = currentSlideNumber < (presentation.Slides.Count - 1);
        buttonPrev.Enabled = currentSlideNumber > 0;
    }

    private void ShowSlide(int slideNumber)
    {
        Aspose.Slides.Drawing.Xamarin.Size size = presentation.SlideSize.Size.ToSize();
        Aspose.Slides.Drawing.Xamarin.Bitmap bitmap = presentation.Slides[slideNumber].GetThumbnail(size);
        imageView.SetImageBitmap(bitmap.ToNativeBitmap());
    }

    private void LoadPresentation()
    {
        if(presentation != null)
        {
            return;
        }

        using (Stream input = Assets.Open("HelloWorld.pptx"))
        {
            presentation = new Aspose.Slides.Presentation(input);
        }
    }

    private void DisposePresentation()
    {
        if(presentation == null)
        {
            return;
        }
        
        presentation.Dispose();
        presentation = null;
    }

}

أخيرًا، لننفّذ دالة لإضافة شكل بيضاوي عند لمس الشريحة:

C# - MainActivity.cs - إضافة بيضاوي عند النقر على الشريحة

 private void ImageView_Touch(object sender, Android.Views.View.TouchEventArgs e)
{
    int[] location = new int[2];
    imageView.GetLocationOnScreen(location);
    int x = (int)e.Event.GetX();
    int y = (int)e.Event.GetY();
    int posX = x - location[0];
    int posY = y - location[0];
    
    Aspose.Slides.Drawing.Xamarin.Size presSize = presentation.SlideSize.Size.ToSize();

    float coeffX = (float)presSize.Width / imageView.Width;
    float coeffY = (float)presSize.Height / imageView.Height;
    int presPosX = (int)(posX * coeffX);
    int presPosY = (int)(posY * coeffY);
    int width = presSize.Width / 50;

    int height = width;
    Aspose.Slides.IAutoShape ellipse = presentation.Slides[currentSlideNumber].Shapes.AddAutoShape(Aspose.Slides.ShapeType.Ellipse, presPosX, presPosY, width, height);
    ellipse.FillFormat.FillType = Aspose.Slides.FillType.Solid;

    Random random = new Random();
    Aspose.Slides.Drawing.Xamarin.Color slidesColor = Aspose.Slides.Drawing.Xamarin.Color.FromArgb(random.Next(256), random.Next(256), random.Next(256));
    ellipse.FillFormat.SolidFillColor.Color = slidesColor;
    ShowSlide(currentSlideNumber);
}

كل نقرة على شريحة العرض التقديمي تؤدي إلى إضافة بيضاوي عشوائي اللون:

todo:image_alt_text

الميزات المدعومة

الميزات Aspose.Slides لـ .NET Aspose.Slides لـ Xamarin
ميزات العرض التقديمي:
إنشاء عروض تقديمية جديدة tick tick
صيغ PowerPoint 97 - 2003 فتح/حفظ tick tick
صيغ PowerPoint 2007 فتح/حفظ tick tick
دعم امتدادات PowerPoint 2010 tick tick
دعم امتدادات PowerPoint 2013 tick tick
دعم ميزات PowerPoint 2016 restricted restricted
دعم ميزات PowerPoint 2019 restricted restricted
تحويل PPT إلى PPTX tick tick
تحويل PPTX إلى PPT tick tick
PPTX داخل PPT restricted restricted
معالجة القوالب tick tick
معالجة الماكرو tick tick
معالجة خصائص المستند tick tick
حماية كلمة المرور tick tick
استخراج النص السريع tick tick
دمج الخطوط tick tick
عرض التعليقات tick tick
مقاطعة المهام الطويلة tick tick
تنسيقات التصدير:
PDF tick tick
XPS tick tick
HTML tick tick
TIFF tick circle
ODP restricted restricted
SWF restricted restricted
SVG tick tick
تنسيقات الاستيراد:
HTML restricted restricted
ODP tick tick
THMX tick tick
ميزات الشرائح الرئيسية:
الوصول إلى جميع الشرائح الرئيسية الموجودة tick tick
إنشاء/إزالة الشرائح الرئيسية tick tick
استنساخ الشرائح الرئيسية tick tick
ميزات شرائح التخطيط:
الوصول إلى جميع شرائح التخطيط الموجودة tick tick
إنشاء/إزالة شرائح التخطيط tick tick
استنساخ شرائح التخطيط tick tick
ميزات الشريحة:
الوصول إلى جميع الشرائح الموجودة tick tick
إنشاء/إزالة الشرائح tick tick
استنساخ الشرائح tick tick
تصدير الشرائح إلى صور tick tick
إنشاء/تحرير/إزالة أقسام الشريحة tick tick
ميزات شرائح الملاحظات:
الوصول إلى جميع شرائح الملاحظات الموجودة tick tick
ميزات الشكل:
الوصول إلى جميع أشكال الشرائح tick tick
إضافة أشكال جديدة tick tick
استنساخ الأشكال tick tick
تصدير الأشكال المنفصلة إلى صور tick tick
أنواع الأشكال المدعومة:
جميع أنواع الأشكال المعرّفة مسبقًا tick tick
إطارات الصور tick tick
الجداول tick tick
المخططات tick tick
SmartArt tick tick
مخطط قديم tick tick
WordArt tick tick
كائنات OLE, ActiveX restricted restricted
إطارات الفيديو tick tick
إطارات الصوت tick tick
الروابط tick tick
ميزات مجموعة الأشكال:
الوصول إلى مجموعات الأشكال tick tick
إنشاء مجموعات الأشكال tick tick
فك تجميع مجموعات الأشكال الموجودة tick tick
ميزات تأثيرات الشكل:
تأثيرات 2D restricted restricted
تأثيرات 3D circle circle
ميزات النص:
تنسيق الفقرات tick tick
تنسيق الأقسام tick tick
ميزات الرسوم المتحركة:
تصدير الرسوم المتحركة إلى SWF circle circle
تصدير الرسوم المتحركة إلى HTML circle circle