Step 1- Open Visual Studio->New Project->Templates->Visual C#->Android->Blank app.
Select Blank app. Give project name and project location.

Step 2- Open Solution Explorer-> Project Name->Resources->Layout->Main.axml. Click Open Design View.
Step 3- Go to Tool bar, select button and ImageView. Drag and drop Main.xaml design view.

Step 4- Go to Solution Explorer-> Project Name. Right click to Add->Class, followed by opening new Dialog box. This dialog box is required to select the class and give name for BitmapHelpers.cs.

Step 5- Open Solution Explorer-> Project Name->Resources-> BitmapHelpers.cs. This class is reducing the image size and recycling the memory. It will be used to calculate an image ratio.

C# Code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Android.App;
- using Android.Content;
- using Android.OS;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- using Android.Graphics;
- using Android.Graphics.Drawables;
- namespace Camera {
- public static class BitmapHelpers {
- /// This method will recyle the memory help by a bitmap in an ImageView
- public static void RecycleBitmap(this ImageView imageView) {
- if (imageView == null) {
- return;
- }
- Drawable toRecycle = imageView.Drawable;
- if (toRecycle != null) {
- ((BitmapDrawable) toRecycle).Bitmap.Recycle();
- }
- }
- /// Load the image from the device, and resize it to the specified dimensions.
- public static Bitmap LoadAndResizeBitmap(this string fileName, int width, int height) {
- // First we get the the dimensions of the file on disk
- BitmapFactory.Options options = new BitmapFactory.Options {
- InPurgeable = true,
- InJustDecodeBounds = true
- };
- BitmapFactory.DecodeFile(fileName, options);
- // Next we calculate the ratio that we need to resize the image by
- // in order to fit the requested dimensions.
- int outHeight = options.OutHeight;
- int outWidth = options.OutWidth;
- int inSampleSize = 1;
- if (outHeight > height || outWidth > width) {
- inSampleSize = outWidth > outHeight ? outHeight / height : outWidth / width;
- }
- // Now we will load the image and have BitmapFactory resize it for us.
- options.InSampleSize = inSampleSize;
- options.InJustDecodeBounds = false;
- Bitmap resizedBitmap = BitmapFactory.DecodeFile(fileName, options);
- return resizedBitmap;
- }
- }
- }






Rex ConacoPosted Sep 20, 2019, 8:26 PM
I cant preview capture picture in image view, please help
Peter MagedPosted Mar 30, 2019, 8:25 AM
Unhandled Exception:Android.OS.FileUriExposedException: file:///storage/emulated/0/Pictures/Application%20images/Image_2e5909c4-15a6-4f9d-9fd5-00dcbd509afb.jpg exposed beyond app through ClipData.Item.getUri() occurred
Prasanna MuraliPosted Sep 13, 2016, 12:57 AM
Nice post..
SubashPosted Sep 13, 2016, 12:04 AM
Very nice one
Anu VPosted Sep 12, 2016, 11:46 PM
Nice..