捏缩放Xamarin中的图像 [英] Pinch zooming on an image in Xamarin
问题描述
在 Xamarin
中,为图像启用缩放缩放的最佳方法是什么?目前我只有一个 ImageView
,它有一个 Bitmap
图像作为图像。
我做了一些研究,我找到了一些例子,其中人们使用了其他一些库,但是在我开始编写这段代码之前,想要一些关于在图像上启用缩放缩放的最佳方法的建议。 / p>
那么,在 Android
中对图像进行缩放缩放的最佳方法是什么,特别是 Xamarin
?
提前感谢
您可以使用Monodroidtoolkit ScaleImageView获取ImageView放大功能并放大放大的图像。
首先,使用此处的代码。
该工具包还有一个如何使用它的示例,基本上你添加这样的活动:
namespace Sample
{
[Activity(Label =My Activity)]
public class ScaleImageActivity :Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.ScaleImage);
}
}
}
然后,添加 ScaleImage.axml 布局使用以下XML:
< 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有一个包含这一个样本的项目
In Xamarin
, what is the best way to enable pinch zooming for an image? Currently I have just an ImageView
that has a Bitmap
image as an image.
I have done some research, and I have found a few examples where people have used some other libraries but would like some advice on the best way to enable pinch zooming on an image before I start writing this code.
So, what is the best way to enable pinch zooming on an image in Android
, specifically Xamarin
?
Thank in advance
You can get ImageView zoom-in capabilities and panning of the zoomed in image by using the Monodroidtoolkit ScaleImageView.
First, add the ScaleImageView.cs class to your project using the code from here.
The toolkit also has a sample of how to use it, basically you add an activity like this:
namespace Samples
{
[Activity(Label = "My Activity")]
public class ScaleImageActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.ScaleImage);
}
}
}
Then, add the ScaleImage.axml layout by creating a layout with the following XML:
<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>
Finally, in this sample it is loading an image of Seattle from the drawable folder, so add the seattle.jpg image which can be found here
The MonoDroidToolkit has a project with a bunch of samples including this one
这篇关于捏缩放Xamarin中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!