Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pinch zooming on an image in Xamarin

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

like image 943
user3736648 Avatar asked Jun 22 '14 13:06

user3736648


1 Answers

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

like image 150
mkimmet Avatar answered Oct 12 '22 10:10

mkimmet