public override void Draw(Canvas canvas) { RoundedBoxView rbv = (RoundedBoxView)this.Element; Rect rc = new Rect(); GetDrawingRect(rc); Rect interior = rc; interior.Inset((int)rbv.BorderThickness, (int)rbv.BorderThickness); Paint p = new Paint() { Color = rbv.BackgroundColor.ToAndroid(), AntiAlias = true, }; var radius = (float)(rc.Width() / rbv.Width * rbv.CornerRadius); //canvas.DrawRoundRect(new RectF(interior), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p); canvas.DrawRoundRect(new RectF(interior), radius, radius, p); // Draw border if (rbv.BorderThickness > 0) { p.Color = rbv.BorderColor.ToAndroid(); p.StrokeWidth = (float)rbv.BorderThickness; p.SetStyle(Paint.Style.Stroke); //canvas.DrawRoundRect(new RectF(rc), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p); canvas.DrawRoundRect(new RectF(rc), radius, radius, p); } }
// Grows the cropping rectange by (dx, dy) in image space. private void moveBy(float dx, float dy) { Rect invalRect = new Rect(DrawRect); cropRect.Offset(dx, dy); // Put the cropping rectangle inside image rectangle. cropRect.Offset( Math.Max(0, imageRect.Left - cropRect.Left), Math.Max(0, imageRect.Top - cropRect.Top)); cropRect.Offset( Math.Min(0, imageRect.Right - cropRect.Right), Math.Min(0, imageRect.Bottom - cropRect.Bottom)); DrawRect = computeLayout(); invalRect.Union(DrawRect); invalRect.Inset(-10, -10); context.Invalidate(invalRect); }
/// <summary> /// Crops the image /// </summary> internal Bitmap Crop() { try { // TODO this code needs to change to use the decode/crop/encode single // step api so that we don't require that the whole (possibly large) // bitmap doesn't have to be read into memory if (saving) { return null; } saving = true; var r = highlightView.CropRect; int width = r.Width(); int height = r.Height(); Bitmap croppedImage = Bitmap.CreateBitmap(width, height, Bitmap.Config.Rgb565); { Canvas canvas = new Canvas(croppedImage); Rect dstRect = new Rect(0, 0, width, height); canvas.DrawBitmap(bitmap, r, dstRect, null); } // If the output is required to a specific size then scale or fill if (OutputWidth != 0 && OutputHeight != 0) { if (scaleImage) { // Scale the image to the required dimensions Bitmap old = croppedImage; croppedImage = Util.transform(new Matrix(), croppedImage, OutputWidth, OutputHeight, scaleUp); if (old != croppedImage) { old.Recycle(); } } else { // Don't scale the image crop it to the size requested. // Create an new image with the cropped image in the center and // the extra space filled. Bitmap b = Bitmap.CreateBitmap(OutputWidth, OutputHeight, Bitmap.Config.Rgb565); Canvas canvas = new Canvas(b); Rect srcRect = highlightView.CropRect; Rect dstRect = new Rect(0, 0, OutputWidth, OutputHeight); int dx = (srcRect.Width() - dstRect.Width()) / 2; int dy = (srcRect.Height() - dstRect.Height()) / 2; // If the srcRect is too big, use the center part of it. srcRect.Inset(Math.Max(0, dx), Math.Max(0, dy)); // If the dstRect is too big, use the center part of it. dstRect.Inset(Math.Max(0, -dx), Math.Max(0, -dy)); // Draw the cropped bitmap in the center canvas.DrawBitmap(bitmap, srcRect, dstRect, null); // Set the cropped bitmap as the new bitmap croppedImage.Recycle(); croppedImage = b; } } return croppedImage; //SaveOutput(croppedImage, destinationUri); } catch (Exception ex) { Log.Error(this.GetType().Name, ex.Message); } finally { saving = false; } return null; }
private void onSaveClicked() { // TODO this code needs to change to use the decode/crop/encode single // step api so that we don't require that the whole (possibly large) // bitmap doesn't have to be read into memory if (Saving) { return; } Saving = true; var r = Crop.CropRect; int width = r.Width(); int height = r.Height(); Bitmap croppedImage = Bitmap.CreateBitmap(width, height, Bitmap.Config.Rgb565); { Canvas canvas = new Canvas(croppedImage); Rect dstRect = new Rect(0, 0, width, height); canvas.DrawBitmap(bitmap, r, dstRect, null); } // If the output is required to a specific size then scale or fill if (outputX != 0 && outputY != 0) { if (scale) { // Scale the image to the required dimensions Bitmap old = croppedImage; croppedImage = Util.transform(new Matrix(), croppedImage, outputX, outputY, scaleUp); if (old != croppedImage) { old.Recycle(); } } else { // Don't scale the image crop it to the size requested. // Create an new image with the cropped image in the center and // the extra space filled. Bitmap b = Bitmap.CreateBitmap(outputX, outputY, Bitmap.Config.Rgb565); Canvas canvas = new Canvas(b); Rect srcRect = Crop.CropRect; Rect dstRect = new Rect(0, 0, outputX, outputY); int dx = (srcRect.Width() - dstRect.Width()) / 2; int dy = (srcRect.Height() - dstRect.Height()) / 2; // If the srcRect is too big, use the center part of it. srcRect.Inset(Math.Max(0, dx), Math.Max(0, dy)); // If the dstRect is too big, use the center part of it. dstRect.Inset(Math.Max(0, -dx), Math.Max(0, -dy)); // Draw the cropped bitmap in the center canvas.DrawBitmap(bitmap, srcRect, dstRect, null); // Set the cropped bitmap as the new bitmap croppedImage.Recycle(); croppedImage = b; } } // Return the cropped image directly or save it to the specified URI. Bundle myExtras = Intent.Extras; if (myExtras != null && (myExtras.GetParcelable("data") != null || myExtras.GetBoolean("return-data"))) { Bundle extras = new Bundle(); extras.PutParcelable("data", croppedImage); SetResult(Result.Ok, (new Intent()).SetAction("inline-data").PutExtras(extras)); Finish(); } else { Bitmap b = croppedImage; BackgroundJob.StartBackgroundJob(this, null, "Saving image", () => saveOutput(b), mHandler); } }
protected override void OnDraw (Canvas canvas) { _rect = canvas.ClipBounds; _rect.Inset(0, -_height / 2); canvas.ClipRect(_rect, Region.Op.Replace); if (!_isUserTouching) { if (DeltaY > -_maxCurvature && DeltaY < _maxCurvature) Curvature = DeltaY * 2; TopCellPath(OneFifthWidth, FourFifthWith, Curvature); BottomCellPath(FourFifthWith, OneFifthWidth, _height + Curvature); } else { float Curvatured = _isSelectedView?-Curvature:Curvature; TopCellPath(_fingerX,_fingerX,Curvatured); Curvatured = _isSelectedView?_height-Curvatured:_height; BottomCellPath(_fingerX,_fingerX,Curvatured); } canvas.DrawPath(_path, _paint); }