// For each face, we create a HightlightView for it. private void HandleFace(FaceDetector.Face f) { EmCropImage eci = this.ECI; if (eci == null) { return; } PointF midPoint = new PointF(); int r = ((int)(f.EyesDistance() * this.Scale)) * 2; f.GetMidPoint(midPoint); midPoint.X *= this.Scale; midPoint.Y *= this.Scale; int midX = (int)midPoint.X; int midY = (int)midPoint.Y; EmHighlightView hv = new EmHighlightView(eci.ImageView, eci.MOutlineColor, eci.MOutlineCircleColor); int width = eci.Bitmap.Width; int height = eci.Bitmap.Height; Rect imageRect = new Rect(0, 0, width, height); RectF faceRect = new RectF(midX, midY, midX, midY); faceRect.Inset(-r, -r); if (faceRect.Left < 0) { faceRect.Inset(-faceRect.Left, -faceRect.Left); } if (faceRect.Top < 0) { faceRect.Inset(-faceRect.Top, -faceRect.Top); } if (faceRect.Right > imageRect.Right) { faceRect.Inset(faceRect.Right - imageRect.Right, faceRect.Right - imageRect.Right); } if (faceRect.Bottom > imageRect.Bottom) { faceRect.Inset(faceRect.Bottom - imageRect.Bottom, faceRect.Bottom - imageRect.Bottom); } hv.Setup(this.MImageMatrix, imageRect, faceRect, eci.CircleCropping, eci.AspectX != 0 && eci.AspectY != 0); eci.ImageView.Add(hv); }
private void MakeDefault() { EmCropImage eci = this.ECI; if (eci == null) { return; } EmHighlightView hv = new EmHighlightView(eci.ImageView, eci.MOutlineColor, eci.MOutlineCircleColor); int width = eci.Bitmap.Width; int height = eci.Bitmap.Height; Rect imageRect = new Rect(0, 0, width, height); // make the default size about 4/5 of the width or height int cropWidth = Java.Lang.Math.Min(width, height) * 4 / 5; int cropHeight = cropWidth; if (eci.AspectX != 0 && eci.AspectY != 0) { if (eci.AspectX > eci.AspectY) { cropHeight = cropWidth * eci.AspectY / eci.AspectX; } else { cropWidth = cropHeight * eci.AspectX / eci.AspectY; } } int x = (width - cropWidth) / 2; int y = (height - cropHeight) / 2; RectF cropRect = new RectF(x, y, x + cropWidth, y + cropHeight); hv.Setup(this.MImageMatrix, imageRect, cropRect, eci.CircleCropping, eci.AspectX != 0 && eci.AspectY != 0); eci.ImageView.Add(hv); }