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