【问题标题】:Pinch zooming on an image in Xamarin在 Xamarin 中缩放图像
【发布时间】:2014-08-12 15:36:32
【问题描述】:

Xamarin 中,为图像启用双指缩放的最佳方式是什么?目前我只有一个ImageView,其中有一个Bitmap 图像作为图像。

我进行了一些研究,发现了一些示例,其中人们使用了其他一些库,但在我开始编写此代码之前,希望获得一些关于在图像上启用双指缩放的最佳方法的建议。

那么,在Android,特别是Xamarin 中启用双指缩放的最佳方法是什么?

提前致谢

【问题讨论】:

    标签: android image xamarin pinchzoom android-bitmap


    【解决方案1】:

    您可以使用 Monodroidtoolkit ScaleImageView 获得 ImageView 放大功能和放大图像的平移。

    首先,使用 the code from here 将 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 文件夹中加载了西雅图的图像,所以添加可以在 here 找到的 seattle.jpg 图像

    MonoDroidToolkit 有一个包含大量示例的项目,包括这个

    【讨论】:

      猜你喜欢
      • 2019-10-31
      • 2020-05-04
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-08
      • 2013-05-29
      • 2021-07-13
      相关资源
      最近更新 更多