Introduction
This article demonstrates how to add the Zoom Image functionality in an Android application using Xamarin.Forms. Xamarin is a platform that allows us to create a multi-platform mobile applications for platforms, like Android, Windows, iOS through a single integrated development environment (IDE). And with Xamarin. Forms, the interface design for all three platform can be accomplished within its XAML-based standard, native user-interface control.
Step 1
Open Visual Studio and go to New Project >> Installed >> Visual C# >> Cross-Platform.
Select Cross-Platform app, then give your project a name and location and click "OK" button.
Step 2
Next, add an image to Solution Explorer >> Project Name.Android >> Resources >> Right Click >> Drawable >> Add >> Existing Item. When we click an existing item button, it opens a dialogue box.
Next, add an image to Solution Explorer >> Project Name.Android >> Resources >> Right Click >> Drawable >> Add >> Existing Item. When we click an existing item button, it opens a dialogue box.
Choose image location and add images.
.

The image is added successfully. Then move the cursor to that image and just verify the image.
Step 3
Next, go to Project Name (Portable) >> Right-Click >> Add >> NewFolder. Select the new folder, the Dialogue Box will open. Just give the folder Name and Click "Add" button. The folder name is"Extensions".
Step 4
Now, go to Open Solution Explorer >> Project Name (Portable) >> Extensions >> Right-Click >> Add >> Class. When you click the class button it will open the dialogue.
The class name is "DoubleExtensions".
Step 5
Next, go to Open Solution Explorer >> Project Name (Portable) >> Extensions >> DubleExtensions.cs >> Left-Click in Open the DoubleExtensions.cs page.
The code is given below just copy it.
C# Code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Image_Zoom.Extensions
- {
- public static class DoubleExtensions
- {
- public static double Clamp(this double self, double min, double max)
- {
- return Math.Min(max, Math.Max(self, min));
- }
- }
- }
Step 6
Now, Open Solution Explorer >> Project Name(Portable) >> MainPage.Xaml. Double click for opening the design view of this page.
The code is given below just copy it.
XAML Code
We are adding an image inside the grid.
- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- xmlns:local="clr-namespace:Image_Zoom"
- x:Class="Image_Zoom.MainPage">
- <ContentPage.Content>
- <Grid Padding="20">
- <local:PinchToZoomContainer>
- <local:PinchToZoomContainer.Content>
- <Image Source="Android.png" />
- </local:PinchToZoomContainer.Content>
- </local:PinchToZoomContainer>
- </Grid>
- </ContentPage.Content>
- </ContentPage>

L PPosted Oct 23, 2019, 10:39 AM
You ought to acknowledge that your code is virtually identical to the Microsoft documentation here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/gestures/pinch
Munish APosted Jun 5, 2018, 9:39 PM
Nice article keep sharing.........