private void SetupDrawingCanvas() { path = XForm.GetValue(Binding.nodeset); if (!string.IsNullOrEmpty(path)) { Bitmap bitmap = BitmapFactory.DecodeFile(path); //grab the exif note if there is one ExifInterface exifData = new ExifInterface(path); string note = exifData.GetAttribute(ExifInterface.TagImageDescription); if (note != null) { EditExif.Text = note; } //grab orientation if there is one, some images from the net may not even have it int orientation = exifData.GetAttributeInt(Android.Media.ExifInterface.TagOrientation, 1); switch (orientation) { case 6: bitmap = BitmapHelpers.RotateBitmap(bitmap, 90f); break; case 3: bitmap = BitmapHelpers.RotateBitmap(bitmap, 180f); break; case 8: bitmap = BitmapHelpers.RotateBitmap(bitmap, 270f); break; } Dims = new int[] { bitmap.Width, bitmap.Height }; //this one liner does all, gets the lower of the two to determine what to scale it by decimal scale = Math.Min(Decimal.Divide(MainCanvas.Width, Dims[0]), Decimal.Divide(MainCanvas.Height, Dims[1])); int width = (int)(Dims[0] * scale); int height = (int)(Dims[1] * scale); //background image if (Control.appearance.ToLower() == "annotate" || Control.appearance.ToLower() == "textannotate") { bitmap = Bitmap.CreateScaledBitmap(bitmap, width, height, true); BackgroundImage.SetImageBitmap(bitmap); } //canvas image if (TempBitmap != null) { canvasBitmap = Bitmap.CreateScaledBitmap(TempBitmap, width, height, true); } else { canvasBitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); } if (dv == null) { dv = new DrawingView(this, canvasBitmap, 10, BackgroundImage); } if (Control.appearance.ToLower() != "signature") { SetupEvents(); } var layoutParams = new RelativeLayout.LayoutParams(width, height); layoutParams.AddRule(LayoutRules.CenterInParent); dv.LayoutParameters = layoutParams; MainCanvas.AddView(dv); GC.Collect(); } else if (Control.appearance.ToLower() == "signature" || Control.appearance.ToLower() == "draw") { int width = MainCanvas.Width; int height = MainCanvas.Height; //canvas image if (TempBitmap != null) { canvasBitmap = Bitmap.CreateScaledBitmap(TempBitmap, width, height, true); } else { canvasBitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); } if (dv == null) { dv = new DrawingView(this, canvasBitmap, 10, BackgroundImage); } if (Control.appearance.ToLower() != "signature") { SetupEvents(); } var layoutParams = new RelativeLayout.LayoutParams(width, height); layoutParams.AddRule(LayoutRules.CenterInParent); dv.LayoutParameters = layoutParams; MainCanvas.AddView(dv); GC.Collect(); } }