public void SetImageRotateBitmapResetBase(RotateBitmap bitmap, bool resetSupp) { if (Width <= 0) { onLayoutRunnable = () => SetImageRotateBitmapResetBase(bitmap, resetSupp); return; } if (bitmap.Bitmap != null) { GetProperBaseMatrix(bitmap, baseMatrix); SetImageBitmap(bitmap.Bitmap, bitmap.Rotation); } else { baseMatrix.Reset(); base.SetImageBitmap(null); } if (resetSupp) { suppMatrix.Reset(); } ImageMatrix = GetImageViewMatrix(); maxZoom = CalculateMaxZoom(); }
private void OnRotateClicked(int degree) { _bitmap.RotateImage(degree); var rotateBitmap = new RotateBitmap(_bitmap); _imageView.SetImageRotateBitmapResetBase(rotateBitmap, true); AddHighlightView(); }
/// <summary> /// Setup the base MatrixImage so that the image is centered and scaled properly. /// </summary> private void GetProperBaseMatrix(RotateBitmap bitmap, Matrix matrix) { float viewWidth = Width; float viewHeight = Height; float w = bitmap.Width; float h = bitmap.Height; int rotation = bitmap.Rotation; matrix.Reset(); // We limit up-scaling to 2x otherwise the result may look bad if it's // a small icon. float widthScale = Math.Min(viewWidth / w, 2.0f); float heightScale = Math.Min(viewHeight / h, 2.0f); float scale = Math.Min(widthScale, heightScale); matrix.PostConcat(bitmap.GetRotateMatrix()); matrix.PostScale(scale, scale); matrix.PostTranslate( (viewWidth - w * scale) / 2F, (viewHeight - h * scale) / 2F); }