Beispiel #1
0
        private void AddHighlightView(Bitmap bitmap)
        {
            if (bitmap == null)
                return;

            highlightView = new HighlightView(this);

            int width = bitmap.Width;
            int height = bitmap.Height;

            Rect imageRect = new Rect(0, 0, width, height);

            
            // make the default size about 4/5 of the width or height
            int cropWidth = width * 4 / 5; //Math.Min(width, height) * 4 / 5;
            int cropHeight = height * 4 / 5;

            if (OutputWidth != 0 && OutputHeight != 0)
            {
                if(OutputWidth < OutputHeight)
                {
                    var aspectRatio =  (float)OutputWidth / (float)OutputHeight;
                    cropWidth = (int)(cropHeight * aspectRatio);
                }
                else
                {
                    var aspectRatio = (float)OutputHeight / (float)OutputWidth;
                    cropHeight = (int)(cropWidth * aspectRatio);
                }
            }

            int x = (width - cropWidth) / 2;
            int y = (height - cropHeight) / 2;

            RectF cropRect = new RectF(x, y, x + cropWidth, y + cropHeight);

            highlightView.Setup(this.ImageMatrix, imageRect, cropRect, OutputWidth != 0 && OutputHeight != 0);

            this.ClearHighlightViews();
            highlightView.Focused = true;
            this.AddHighlightView(highlightView);

            Center(true, true);
        }