在Xamarin中对图片进行捏合缩放

6
在Xamarin中,如何为图像启用捏合缩放是最佳方式?目前我只有一个ImageView,其中包含一个Bitmap图像。
我做了一些研究,并找到了一些人使用其他库的示例,但在开始编写此代码之前,想了解在Android中特别是Xamarin中启用图像捏合缩放的最佳方法是什么。
提前感谢。
1个回答

12
您可以通过使用Monodroidtoolkit ScaleImageView来获得ImageView的缩放功能和缩放后图像的平移。
首先,使用此处的代码将ScaleImageView.cs类添加到您的项目中。
该工具包还有一个如何使用它的示例,基本上您需要添加一个activity,如下所示:
namespace Samples
{
    [Activity(Label = "My Activity")]
    public class ScaleImageActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.ScaleImage);
        }
    }
}

接着,通过创建以下XML布局并添加ScaleImage.axml布局来完成:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<com.refractored.monodroidtoolkit.ScaleImageView
  android:layout_width="fill_parent"
    android:layout_height="fill_parent"
  android:src="@drawable/seattle"
  android:id="@+id/AnimateImage">
</com.refractored.monodroidtoolkit.ScaleImageView>
</LinearLayout>

最后,在这个示例中,它正在从drawable文件夹加载西雅图的图像,因此请添加可以在这里找到的seattle.jpg图像。

MonoDroidToolkit有一个包含许多示例的项目,包括此示例。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接