/// <summary> /// This method will determine the scaling ratio for the image view. /// </summary> /// <param name="startBounds">The visible rectangle of the thumbnail.</param> /// <param name="finalBounds">The visible rectangle of the expanded image view.</param> /// <returns></returns> private static float CalculateStartScale(Rect startBounds, Rect finalBounds) { float startScale; // First figure out width-to-height ratio of each rectangle. float finalBoundsRatio = finalBounds.Width() / (float)finalBounds.Height(); float startBoundsRatio = startBounds.Width() / (float)startBounds.Height(); if (finalBoundsRatio > startBoundsRatio) { // Extend start bounds horizontally startScale = (float)startBounds.Height() / finalBounds.Height(); float startWidth = startScale * finalBounds.Width(); float deltaWidth = (startWidth - startBounds.Width()) / 2; startBounds.Left -= (int)deltaWidth; startBounds.Right += (int)deltaWidth; } else { // Extend start bounds vertically startScale = (float)startBounds.Width() / finalBounds.Width(); float startHeight = startScale * finalBounds.Height(); float deltaHeight = (startHeight - startBounds.Height()) / 2; startBounds.Top -= (int)deltaHeight; startBounds.Bottom += (int)deltaHeight; } return startScale; }
protected override void OnDraw(Canvas canvas) { base.OnDraw (canvas); var r = new Rect (); this.GetLocalVisibleRect (r); var half = r.Width() / 2; var height = r.Height(); var percentage = (this.Limit - Math.Abs(this.CurrentValue)) / this.Limit; var paint = new Paint() { Color = this.CurrentValue < 0 ? this.negativeColor : this.positiveColor, StrokeWidth = 5 }; paint.SetStyle(Paint.Style.Fill); if (this.CurrentValue < 0) { var start = (float)percentage * half; var size = half - start; canvas.DrawRect (new Rect ((int)start, 0, (int)(start + size), height), paint); } else { canvas.DrawRect (new Rect((int)half, 0, (int)(half + percentage * half), height), paint); } }
public Bitmap GetBitmapMarker(Context mContext, int resourceId, string text) { Resources resources = mContext.Resources; float scale = resources.DisplayMetrics.Density; Bitmap bitmap = BitmapFactory.DecodeResource(resources, resourceId); Bitmap.Config bitmapConfig = bitmap.GetConfig(); // set default bitmap config if none if (bitmapConfig == null) bitmapConfig = Bitmap.Config.Argb8888; bitmap = bitmap.Copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(PaintFlags.AntiAlias); paint.Color = global::Android.Graphics.Color.Black; paint.TextSize = ((int)(14 * scale)); paint.SetShadowLayer(1f, 0f, 1f, global::Android.Graphics.Color.White); // draw text to the Canvas center Rect bounds = new Rect(); paint.GetTextBounds(text, 0, text.Length, bounds); int x = (bitmap.Width - bounds.Width()) / 2; int y = (bitmap.Height + bounds.Height()) / 2 - 20; canvas.DrawText(text, x, y, paint); return bitmap; }
//http://egoco.de/post/19077604048/calculating-the-height-of-text-in-android //http://stackoverflow.com/questions/16082359/how-to-auto-adjust-text-size-on-a-multi-line-textview-according-to-the-view-max public SizeF MeasureString(string text, int maxWidth = 2147483647) { TextPaint paint = AndroidBrush.CreateTextPaint(); paint.TextSize = SizeInPoints; paint.SetTypeface(InnerFont); int lineCount = 0; int index = 0; int length = text.Length; float[] measuredWidths = new float[]{ 0 }; float measuredWidth = 1f; while(index < length - 1) { index += paint.BreakText(text, index, length, true, maxWidth, measuredWidths); lineCount++; if (measuredWidth < measuredWidths[0]) measuredWidth = measuredWidths[0]; } Rect bounds = new Rect(); paint.GetTextBounds("Py", 0, 2, bounds); float height = (float)System.Math.Floor((double)lineCount * bounds.Height()); return new SizeF (measuredWidth, height); }
public override void Draw(Canvas canvas) { LoadResources (); var blackPaint = new Paint () { Color = black.Value }; var whitePaint = new Paint () { Color = white.Value }; XamGame.RenderBoard ((RectangleF rect, Square.ColourNames color) => { var paint = color == Square.ColourNames.White ? whitePaint : blackPaint; canvas.DrawRect (rect.X, rect.Y, rect.Right, rect.Bottom, paint); }, (RectangleF rect, object image) => { if (image != null) canvas.DrawBitmap ((Bitmap) image, rect.Left, rect.Top, null); }); // New Game button whitePaint.Color = white.Value; whitePaint.SetStyle (Paint.Style.Fill); whitePaint.TextSize = 30; whitePaint.AntiAlias = true; Rect bounds = new Rect (); whitePaint.GetTextBounds ("New Game", 0, 8, bounds); canvas.DrawText ("New Game", (this.Width - bounds.Width ()) / 2, this.Bottom - (XamGame.BoardUpperLeftCorner.Y - bounds.Height ()) / 2, whitePaint); whitePaint.Dispose (); blackPaint.Dispose (); base.Draw (canvas); }
protected override void OnBoundsChange (Rect bounds) { base.OnBoundsChange (bounds); if (oval == null) return; oval.Set (0, 0, bounds.Width (), bounds.Height ()); }
internal void DrawText(string text, Paint p, Typeface font, float size, Rectangle rect, ReoGridHorAlign halign, ReoGridVerAlign valign) { p.SetTypeface(font); p.TextSize = size; var measuredRect = new Rect(); p.GetTextBounds(text, 0, text.Length, measuredRect); float x = rect.Left, y = rect.Top; switch (halign) { case ReoGridHorAlign.General: case ReoGridHorAlign.Left: x = rect.Left; break; case ReoGridHorAlign.Center: x = rect.Left + (rect.Width - measuredRect.Width()) / 2; break; case ReoGridHorAlign.Right: x = rect.Right - measuredRect.Width(); break; } switch (valign) { case ReoGridVerAlign.Top: y = rect.Top + measuredRect.Height(); break; case ReoGridVerAlign.Middle: y = rect.Bottom - (rect.Height - measuredRect.Height()) / 2; break; case ReoGridVerAlign.General: case ReoGridVerAlign.Bottom: y = rect.Bottom; break; } this.canvas.DrawText(text, x, y, p); }
protected override void OnBoundsChange (Rect bounds) { var width = bounds.Width (); var height = bounds.Height (); if (width <= 0 || height <= 0) return; if (Picture != null && (currentBitmap == null || currentBitmap.Height != height || currentBitmap.Width != width)) currentBitmap = SvgFactory.MakeBitmapFromPicture(Picture, width, height); }
public Size Measure(FormattedText formattedText) { var paint = new Paint(); var rect = new Rect(); paint.GetTextBounds(formattedText.Text, 0, formattedText.Text.Length, rect); return(new Size(rect.Width(), rect.Height())); }
public override void Draw(Canvas canvas) { Rect bounds = Bounds; int height = bounds.Height(); paint.TextSize = height; Rect textBounds = new Rect(); string textValue = icon.Character.ToString(); paint.GetTextBounds(textValue, 0, 1, textBounds); int textHeight = textBounds.Height(); float textBottom = bounds.Top + (height - textHeight) / 2f + textHeight - textBounds.Bottom; canvas.DrawText(textValue, bounds.ExactCenterX(), textBottom, paint); }
protected override void OnBoundsChange (Rect bounds) { base.OnBoundsChange (bounds); int height = bounds.Height(); int width = bounds.Width(); numRectanglesHorizontal = (int) Math.Ceiling((double)(width / mRectangleSize)); numRectanglesVertical = (int) Math.Ceiling((double)height / mRectangleSize); generatePatternBitmap(); }
/// <summary> /// get the height of the the string /// </summary> /// <param name="text">the string to measure</param> /// <param name="fontSize">the font size of the displayed string</param> /// <returns>the height of the measured string</returns> public static double TextHeightNative(string text, float fontSize) { Graphics.Rect bounds = new Graphics.Rect(); TextView textView = new TextView(Native.Application.Context) { TextSize = fontSize }; textView.Paint.GetTextBounds(text.ToCharArray(), 0, text.Length, bounds); var height = bounds.Height(); return(height / Resources.System.DisplayMetrics.ScaledDensity); }
public Size Measure(FormattedText formattedText) { var paint = new Paint(); var rect = new Rect(); paint.TextSize = formattedText.FontSize; paint.GetTextBounds(formattedText.Text, 0, formattedText.Text.Length, rect); var descent = paint.Descent(); var height = rect.Height(); var width = rect.Width(); return(new Size(width, height + descent)); }
public SizeF MeasureString(Font font, string text) { if (string.IsNullOrEmpty(text)) // needed to avoid exception { return(SizeF.Empty); } var paint = GetTextPaint(font); // See http://stackoverflow.com/questions/7549182/android-paint-measuretext-vs-gettextbounds var bounds = new ag.Rect(); paint.GetTextBounds(text, 0, text.Length, bounds); // TODO: see the above article; the width may be truncated to the nearest integer. return(new SizeF(bounds.Width(), bounds.Height())); }
protected override void OnBoundsChange (Rect bounds) { base.OnBoundsChange (bounds); mRect.Set (margin, margin, bounds.Width () - margin, bounds.Height () - margin); if (useGradientOverlay) { var colors = new int[] { 0, 0, 0x20000000 }; var pos = new float[] { 0.0f, 0.7f, 1.0f }; RadialGradient vignette = new RadialGradient (mRect.CenterX (), mRect.CenterY () * 1.0f / 0.7f, mRect.CenterX () * 1.3f, colors, pos, Shader.TileMode.Clamp); Matrix oval = new Matrix (); oval.SetScale (1.0f, 0.7f); vignette.SetLocalMatrix (oval); paint.SetShader (new ComposeShader (bitmapShader, vignette, PorterDuff.Mode.SrcOver)); } }
public override Dialog OnCreateDialog(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Begin building a new dialog. var builder = new AlertDialog.Builder(Activity); Rect displayRectangle = new Rect(); Window window = Activity.Window; window.DecorView.GetWindowVisibleDisplayFrame(displayRectangle); var inflater = Activity.LayoutInflater; dateView = inflater.Inflate(Resource.Layout.DateRange, null); dateView.SetMinimumHeight((int)(displayRectangle.Width() * 0.9f)); dateView.SetMinimumHeight((int)(displayRectangle.Height() * 0.9f)); Button butOk = dateView.FindViewById<Button> (Resource.Id.butok); butOk.Click+= ButOk_Click; datePicker1 = DatePicker.NewInstance(SetDateDlg1); datePicker2 = DatePicker.NewInstance(SetDateDlg2); EditText frd = dateView.FindViewById<EditText> (Resource.Id.trxdatefr); EditText tod = dateView.FindViewById<EditText> (Resource.Id.trxdateto); frd.Text = DateTime.Today.ToString ("dd-MM-yyyy"); frd.Click += delegate(object sender, EventArgs e) { datePicker1.Show(FragmentManager, "datePicker"); }; tod.Text = DateTime.Today.ToString ("dd-MM-yyyy"); tod.Click += delegate(object sender, EventArgs e) { datePicker2.Show(FragmentManager, "datePicker2"); }; builder.SetView (dateView); builder.SetPositiveButton ("CANCEL", HandlePositiveButtonClick); var dialog = builder.Create(); //Now return the constructed dialog to the calling activity return dialog; }
public static XIR.Rectangle RemoteRepresentation(this AG.Rect rectangle) => new XIR.Rectangle( rectangle.Left, rectangle.Top, rectangle.Width(), rectangle.Height());
/// <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; }
protected override void OnDraw(Canvas canvas) { if (Element != null && Element.Text != null) { var density = DeviceDisplay.MainDisplayInfo.Density; float strokeWidth = Convert.ToSingle(Element.StrokeWidth * density); float strokeMiter = 10.0f; var rect = new Android.Graphics.Rect(); this.GetDrawingRect(rect); float progressAngle = 360 * Convert.ToSingle(Element.Progress / Element.Total); float radius = Math.Min(rect.Height(), rect.Width()) / 2 - strokeWidth; RectF circleRect = new RectF( rect.ExactCenterX() - radius, rect.ExactCenterY() - radius, rect.ExactCenterX() + radius, rect.ExactCenterY() + radius ); TextPaint paint = new TextPaint(); paint.Color = Element.TextColor.ToAndroid(); paint.TextSize = Element.TextSize; paint.GetTextBounds(Element.Text.ToString(), 0, Element.Text.ToString().Length, rect); if (((this.Width / 2) - (Element.TextMargin * 4)) < rect.Width()) { float ratio = (float)((this.Width / 2) - Element.TextMargin * 4) / (float)rect.Width(); paint.TextSize = paint.TextSize * ratio; paint.GetTextBounds(Element.Text.ToString(), 0, Element.Text.ToString().Length, rect); } int x = this.Width / 2 - rect.CenterX(); int y = this.Height / 2 - rect.CenterY(); Paint progressPaint = new Paint(PaintFlags.AntiAlias) { StrokeWidth = strokeWidth, StrokeMiter = strokeMiter, Color = Element.ProgressStrokeColor.ToAndroid() }; progressPaint.SetStyle(Paint.Style.Stroke); Paint availablePaint = new Paint(PaintFlags.AntiAlias) { StrokeWidth = strokeWidth, StrokeMiter = strokeMiter, Color = Element.AvailableStrokeColor.ToAndroid() }; availablePaint.SetStyle(Paint.Style.Stroke); Paint paintCircle = new Paint(PaintFlags.AntiAlias) { Color = Element.FillColor.ToAndroid() }; canvas.DrawArc(circleRect, -90, progressAngle, false, progressPaint); canvas.DrawArc(circleRect, -90 + progressAngle, 360 - progressAngle, false, availablePaint); canvas.DrawText(Element.Text.ToString(), x, y, paint); } }
private void SetHelpTextMaxHeight(bool arrowOnTop, Rect anchorRect, int yPos) { if (arrowOnTop) { _helpTextView.SetMaxHeight(_displaySize.Y - yPos); } else { _helpTextView.SetMaxHeight(anchorRect.Top - anchorRect.Height()); } }
public Size MeasureText(string text, string fontFamily = null, double fontSize = 10, double fontWeight = 500) { if (string.IsNullOrEmpty(text)) { return Size.Empty; } using (var paint = new Paint()) { paint.AntiAlias = true; paint.TextSize = (float)fontSize; var bounds = new Rect(); paint.GetTextBounds(text, 0, text.Length, bounds); // var width = paint.MeasureText(text); return new Size(bounds.Width(), bounds.Height()); } }
protected override void OnBoundsChange(Rect bounds) { base.OnBoundsChange(bounds); mRectF.Set(0, 0, bounds.Width(), bounds.Height()); }
internal static Bitmap transform(Matrix scaler, Bitmap source, int targetWidth, int targetHeight, bool scaleUp) { int deltaX = source.Width - targetWidth; int deltaY = source.Height - targetHeight; if (!scaleUp && (deltaX < 0 || deltaY < 0)) { // In this case the bitmap is smaller, at least in one dimension, // than the target. Transform it by placing as much of the image // as possible into the target and leaving the top/bottom or // left/right (or both) black. Bitmap b2 = Bitmap.CreateBitmap(targetWidth, targetHeight, Bitmap.Config.Argb8888); Canvas c = new Canvas(b2); int deltaXHalf = Math.Max(0, deltaX / 2); int deltaYHalf = Math.Max(0, deltaY / 2); Rect src = new Rect( deltaXHalf, deltaYHalf, deltaXHalf + Math.Min(targetWidth, source.Width), deltaYHalf + Math.Min(targetHeight, source.Height)); int dstX = (targetWidth - src.Width()) / 2; int dstY = (targetHeight - src.Height()) / 2; Rect dst = new Rect( dstX, dstY, targetWidth - dstX, targetHeight - dstY); c.DrawBitmap(source, src, dst, null); return b2; } float bitmapWidthF = source.Width; float bitmapHeightF = source.Height; float bitmapAspect = bitmapWidthF / bitmapHeightF; float viewAspect = (float)targetWidth / targetHeight; if (bitmapAspect > viewAspect) { float scale = targetHeight / bitmapHeightF; if (scale < .9F || scale > 1F) { scaler.SetScale(scale, scale); } else { scaler = null; } } else { float scale = targetWidth / bitmapWidthF; if (scale < .9F || scale > 1F) { scaler.SetScale(scale, scale); } else { scaler = null; } } Bitmap b1; if (scaler != null) { // this is used for minithumb and crop, so we want to filter here. b1 = Bitmap.CreateBitmap(source, 0, 0, source.Width, source.Height, scaler, true); } else { b1 = source; } int dx1 = Math.Max(0, b1.Width - targetWidth); int dy1 = Math.Max(0, b1.Height - targetHeight); Bitmap b3 = Bitmap.CreateBitmap( b1, dx1 / 2, dy1 / 2, targetWidth, targetHeight); if (b1 != source) { b1.Recycle(); } return b3; }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); canvas.DrawColor(Color.White); this.rootCanvas.SetTarget(canvas); using (var bounds = new Rect()) { canvas.GetClipBounds(bounds); rootCanvas.DrawRectangle(new RectF(bounds.Left, bounds.Top, bounds.Width(), bounds.Height()), Color.Red, Color.Transparent, 0); } }
/// <summary> /// Sets the scan crop to limit decoded area. /// </summary> /// <para> /// ZBar have somewhat changed the coordinate system for defining images. See 'http://stackoverflow.com/a/21258169' for more information /// </para> /// <para> /// The x-axis is defined to strecht the longest side of the image and the y-axis the shortest. /// An image viewed in portrait mode looks like /// (y,0)----------------(0,0) /// | | /// | | /// | | W /// | | i /// | | d /// | | t /// | | h /// | | /// | | /// | | /// |________________| /// (y,x) <- Height -> (x,0) /// </para> /// <param name="rect">Rect defining the scan crop area</param> public void SetCrop(Rect rect) { SetCrop(rect.Left, rect.Top, rect.Height(), rect.Width()); }
void DrawShadow(Canvas canvas) { if (_shadowCanvas == null) { _shadowCanvas = new Canvas(); } if (_shadowPaint == null) { _shadowPaint = new Android.Graphics.Paint { AntiAlias = true, Dither = true, FilterBitmap = true } } ; Graphics.Color solidColor = null; // If need to redraw shadow if (_invalidateShadow) { var viewHeight = _viewBounds.Height(); var viewWidth = _viewBounds.Width(); if (GetChildAt(0) is AView child) { if (viewHeight == 0) { viewHeight = child.MeasuredHeight; } if (viewWidth == 0) { viewWidth = child.MeasuredWidth; } } // If bounds is zero if (viewHeight != 0 && viewWidth != 0) { var bitmapHeight = viewHeight + MaximumRadius; var bitmapWidth = viewWidth + MaximumRadius; // Reset bitmap to bounds _shadowBitmap = Bitmap.CreateBitmap( bitmapWidth, bitmapHeight, Bitmap.Config.Argb8888 ); // Reset Canvas _shadowCanvas.SetBitmap(_shadowBitmap); _invalidateShadow = false; // Create the local copy of all content to draw bitmap as a // bottom layer of natural canvas. base.DispatchDraw(_shadowCanvas); // Get the alpha bounds of bitmap Bitmap extractAlpha = _shadowBitmap.ExtractAlpha(); // Clear past content content to draw shadow _shadowCanvas.DrawColor(Android.Graphics.Color.Black, PorterDuff.Mode.Clear); var shadowOpacity = (float)Shadow.Opacity; if (Shadow.Paint is LinearGradientPaint linearGradientPaint) { var linearGradientShaderFactory = PaintExtensions.GetLinearGradientShaderFactory(linearGradientPaint, shadowOpacity); _shadowPaint.SetShader(linearGradientShaderFactory.Resize(bitmapWidth, bitmapHeight)); } if (Shadow.Paint is RadialGradientPaint radialGradientPaint) { var radialGradientShaderFactory = PaintExtensions.GetRadialGradientShaderFactory(radialGradientPaint, shadowOpacity); _shadowPaint.SetShader(radialGradientShaderFactory.Resize(bitmapWidth, bitmapHeight)); } if (Shadow.Paint is SolidPaint solidPaint) { solidColor = solidPaint.ToColor(); #pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962 _shadowPaint.Color = solidColor.WithAlpha(shadowOpacity).ToPlatform(); #pragma warning restore CA1416 } // Apply the shadow radius var radius = Shadow.Radius; if (radius <= 0) { radius = 0.01f; } if (radius > 100) { radius = MaximumRadius; } _shadowPaint.SetMaskFilter(new BlurMaskFilter(radius, BlurMaskFilter.Blur.Normal)); float shadowOffsetX = (float)Shadow.Offset.X; float shadowOffsetY = (float)Shadow.Offset.Y; if (Clip == null) { _shadowCanvas.DrawBitmap(extractAlpha, shadowOffsetX, shadowOffsetY, _shadowPaint); } else { var bounds = new Graphics.RectF(0, 0, canvas.Width, canvas.Height); var path = Clip.PathForBounds(bounds)?.AsAndroidPath(); path.Offset(shadowOffsetX, shadowOffsetY); _shadowCanvas.DrawPath(path, _shadowPaint); } // Recycle and clear extracted alpha extractAlpha.Recycle(); } else { // Create placeholder bitmap when size is zero and wait until new size coming up _shadowBitmap = Bitmap.CreateBitmap(1, 1, Bitmap.Config.Rgb565 !); } } // Reset alpha to draw child with full alpha if (solidColor != null) #pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962 { _shadowPaint.Color = solidColor.ToPlatform(); } #pragma warning restore CA1416 // Draw shadow bitmap if (_shadowCanvas != null && _shadowBitmap != null && !_shadowBitmap.IsRecycled) { canvas.DrawBitmap(_shadowBitmap, 0.0F, 0.0F, _shadowPaint); } } void ClearShadowResources() { _shadowCanvas?.Dispose(); _shadowPaint?.Dispose(); _shadowBitmap?.Dispose(); _shadowCanvas = null; _shadowPaint = null; _shadowBitmap = null; } }
/// <Docs>The Canvas to which the View is rendered.</Docs> /// <summary> /// Draw the specified canvas. /// </summary> /// <param name="canvas">Canvas to draw onto.</param> public override void Draw(Canvas canvas) { BadgeImage image = (BadgeImage)Element; // Set color of icon if (Control.Drawable != null) { if (image.Selected) { Control.Drawable.SetColorFilter(filterColor); } else { Control.Drawable.SetColorFilter(filterGray); } } base.Draw(canvas); if (image.Number > 0) { using (Paint paint = new Paint()) { paint.Color = image.Selected ? Xamarin.Forms.Color.Red.ToAndroid() : Xamarin.Forms.Color.Gray.ToAndroid(); paint.StrokeWidth = 0f; paint.SetStyle(Paint.Style.FillAndStroke); // Calc text size paint.TextSize = (int)this.DipToPixel(16); paint.FakeBoldText = true; string text = image.Number.ToString(); Rect textBounds = new Rect(0, 0, 0, 0); paint.GetTextBounds(text, 0, text.Length, textBounds); float textWidth = paint.MeasureText(text); float textHeight = textBounds.Height(); float badgeWidth = textWidth + this.DipToPixel(9); float badgeHeight = textHeight + this.DipToPixel(9); if (badgeWidth < badgeHeight) { badgeWidth = badgeHeight; } double offsetX = (image.Bounds.Width - image.Bounds.Width) / 2; double offsetY = (image.Bounds.Height - image.Bounds.Height) / 2; float left = this.DipToPixel(image.Bounds.Width) - badgeWidth; float top = 1; float right = left + badgeWidth; float bottom = top + badgeHeight; float radius = (badgeHeight / 2f) - 1f; using (Path path = new Path()) { canvas.DrawRoundRect(new RectF(left, top, left + badgeWidth, top + badgeHeight), radius, radius, paint); paint.Color = Xamarin.Forms.Color.White.ToAndroid(); canvas.DrawText(image.Number.ToString(), left + ((badgeWidth - textWidth) / 2) - 1, bottom - ((badgeHeight - textHeight) / 2), paint); } } } }
public override void Draw(Canvas canvas) { var bounds = Bounds; var height = bounds.Height(); _paint.TextSize = height; var textBounds = new Rect(); var textValue = _icon.Character.ToString(); _paint.GetTextBounds(textValue, 0, 1, textBounds); var textHeight = textBounds.Height(); var textBottom = bounds.Top + (height - textHeight)/2f + textHeight - textBounds.Bottom; canvas.DrawText(textValue, bounds.ExactCenterX(), textBottom, _paint); }
private void InitializeImages() { if(_pressedImage != null) { _pressedImage.Recycle(); _pressedImage.Dispose(); } if(_unpressedImage != null) { _unpressedImage.Recycle(); _unpressedImage.Dispose(); } _unpressedImage = Bitmap.CreateBitmap(Width, Settings.IsSquared ? Width : Height, Bitmap.Config.Argb8888); _pressedImage = Bitmap.CreateBitmap(Width, Settings.IsSquared ? Width : Height, Bitmap.Config.Argb8888); Canvas unpressedCanvas = new Canvas(_unpressedImage); Canvas pressedCanvas = new Canvas(_pressedImage); Settings.SetTextSize(ComplexUnitType.Px, Settings.TextSize == 0f ? Height * Settings.TextSizeRatio : Settings.TextSize); Settings.StrokeBorderWidth = Height * Settings.StrokeBorderWidthRatio; Settings.StrokeTextWidth = Height * Settings.StrokeTextWidthRatio; // Background fill paint Paint fillBackPaint = new Paint(); fillBackPaint.Color = Settings.FillColor; fillBackPaint.AntiAlias = true; // Background stroke paint Paint strokeBackPaint = new Paint(); strokeBackPaint.Color = Settings.StrokeColor; strokeBackPaint.SetStyle(Paint.Style.Stroke); strokeBackPaint.StrokeWidth = Settings.StrokeBorderWidth; strokeBackPaint.AntiAlias = true; // Text paint Paint textPaint = new Paint(); textPaint.Color = Settings.IsTextStroked ? Settings.FillColor : Settings.StrokeColor; textPaint.TextAlign = Paint.Align.Center; textPaint.TextSize = Settings.TextSize; textPaint.SetTypeface(Settings.Typeface); textPaint.AntiAlias = true; // Text stroke paint Paint strokePaint = new Paint(); strokePaint.Color = Settings.StrokeColor; strokePaint.TextAlign = Paint.Align.Center; strokePaint.TextSize = Settings.TextSize; strokePaint.SetTypeface(Settings.Typeface); strokePaint.SetStyle(Paint.Style.Stroke); strokePaint.StrokeWidth = Settings.StrokeTextWidth; strokePaint.AntiAlias = true; // Background bounds Rect local = new Rect(); this.GetLocalVisibleRect(local); RectF bounds = new RectF(local); bounds.Top += Settings.StrokeBorderWidth/2; bounds.Left += Settings.StrokeBorderWidth/2; bounds.Right -= Settings.StrokeBorderWidth/2; bounds.Bottom -= Settings.StrokeBorderWidth/2; while(bounds.Top > Height) { bounds.Top -= Height; } while(bounds.Bottom > Height) { bounds.Bottom -= Height; } while(bounds.Left > Width) { bounds.Left -= Width; } while(bounds.Right > Width) { bounds.Right -= Width; } // Text location Rect r = new Rect(); strokePaint.GetTextBounds(Text, 0, Text.Length, r); while(r.Width() + Settings.StrokeTextWidth >= bounds.Width()) { Settings.SetTextSize(ComplexUnitType.Px, Settings.TextSize-1); textPaint.TextSize = Settings.TextSize; strokePaint.TextSize = Settings.TextSize; strokePaint.GetTextBounds(Text, 0, Text.Length, r); } float x=0, y=0; switch (Settings.Gravity) { case GravityFlags.Top: y = PaddingTop + r.Height()/2; break; case GravityFlags.Bottom: y = Height - r.Height()/2 - PaddingBottom; break; default: y = Height / 2f + r.Height() / 2f - r.Bottom; break; } switch (Settings.Gravity) { case GravityFlags.Left: x = PaddingLeft + r.Width()/2; break; case GravityFlags.Right: x = Width - r.Width()/2 - PaddingRight; break; default: x = Width/2; break; } // Draw unpressed DrawBackground(unpressedCanvas, bounds, fillBackPaint, strokeBackPaint); if(Settings.IsTextStroked) unpressedCanvas.DrawText(Text, x, y, strokePaint); unpressedCanvas.DrawText(Text, x, y, textPaint); // Change colors fillBackPaint.Color = Settings.StrokeColor; strokeBackPaint.Color = Settings.FillColor; strokePaint.Color = Settings.FillColor; textPaint.Color = Settings.IsTextStroked ? Settings.StrokeColor : Settings.FillColor; // Draw pressed DrawBackground(pressedCanvas, bounds, fillBackPaint, strokeBackPaint); if(Settings.IsTextStroked) pressedCanvas.DrawText(Text, x, y, strokePaint); pressedCanvas.DrawText(Text, x, y, textPaint); // Set images for states StateListDrawable states = new StateListDrawable(); states.AddState(new int[] {Android.Resource.Attribute.StatePressed}, new BitmapDrawable(_pressedImage)); states.AddState(new int[] {Android.Resource.Attribute.StateFocused}, new BitmapDrawable(_pressedImage)); states.AddState(new int[] {Android.Resource.Attribute.StateSelected}, new BitmapDrawable(_pressedImage)); states.AddState(new int[] { }, new BitmapDrawable(_unpressedImage)); SetBackgroundDrawable(states); strokePaint.Dispose(); textPaint.Dispose(); strokeBackPaint.Dispose(); fillBackPaint.Dispose(); unpressedCanvas.Dispose(); pressedCanvas.Dispose(); }
void DrawFace(Canvas canvas, Rect bounds) { var width = bounds.Width(); var height = bounds.Height(); // Draw the background, scaled to fit. if (backgroundScaledBitmap == null || backgroundScaledBitmap.Width != width || backgroundScaledBitmap.Height != height) { backgroundScaledBitmap = Bitmap.CreateScaledBitmap(backgroundBitmap, width, height, true /* filter */); } canvas.DrawColor(Color.Black); canvas.DrawBitmap(backgroundScaledBitmap, 0, 0, null); var centerX = width / 2.0f; var centerY = height / 2.0f; // Draw the ticks. var innerTickRadius = centerX - 10; var outerTickRadius = centerX; for (var tickIndex = 0; tickIndex < 12; tickIndex++) { var tickRot = (float)(tickIndex * Math.PI * 2 / 12); var innerX = (float)Math.Sin(tickRot) * innerTickRadius; var innerY = (float)-Math.Cos(tickRot) * innerTickRadius; var outerX = (float)Math.Sin(tickRot) * outerTickRadius; var outerY = (float)-Math.Cos(tickRot) * outerTickRadius; canvas.DrawLine(centerX + innerX, centerY + innerY, centerX + outerX, centerY + outerY, tickPaint); } }
public static Rectangle ToEto(this ag.Rect rect) { return(new Rectangle(rect.Left, rect.Top, rect.Width(), rect.Height())); }
void DrawHands(Canvas canvas, Rect bounds) { var width = bounds.Width(); var height = bounds.Height(); var centerX = width / 2.0f; var centerY = height / 2.0f; calendar.TimeInMillis = Java.Lang.JavaSystem.CurrentTimeMillis(); var hour = calendar.Get(CalendarField.Hour); var minute = calendar.Get(CalendarField.Minute); var second = calendar.Get(CalendarField.Second); var secRot = second / 30f * (float)Math.PI; var minutes = minute; var minRot = minutes / 30f * (float)Math.PI; var hrRot = ((hour + (minutes / 60f)) / 6f) * (float)Math.PI; var secLength = centerX - 20; var minLength = centerX - 40; var hrLength = centerX - 80; if (!IsInAmbientMode) { var secX = (float)Math.Sin(secRot) * secLength; var secY = (float)-Math.Cos(secRot) * secLength; canvas.DrawLine(centerX, centerY, centerX + secX, centerY + secY, secondPaint); } var minX = (float)Math.Sin(minRot) * minLength; var minY = (float)-Math.Cos(minRot) * minLength; canvas.DrawLine(centerX, centerY, centerX + minX, centerY + minY, minutePaint); var hrX = (float)Math.Sin(hrRot) * hrLength; var hrY = (float)-Math.Cos(hrRot) * hrLength; canvas.DrawLine(centerX, centerY, centerX + hrX, centerY + hrY, hourPaint); }
/// <summary> /// Implement this to do your drawing. /// </summary> /// <param name="canvas">the canvas on which the background will be drawn</param> /// <since version="Added in API level 1" /> /// <remarks> /// <para tool="javadoc-to-mdoc">Implement this to do your drawing.</para> /// <para tool="javadoc-to-mdoc"> /// <format type="text/html"> /// <a href="http://developer.android.com/reference/android/view/View.html#onDraw(android.graphics.Canvas)" /// target="_blank"> /// [Android Documentation] /// </a> /// </format> /// </para> /// </remarks> protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); var r = new Rect(0, 0, canvas.Width, canvas.Height); var dAdjustedThicnkess = (float)Thickness * _dm; var paint = new Paint { Color = StrokeColor, StrokeWidth = dAdjustedThicnkess, AntiAlias = true }; paint.SetStyle(Paint.Style.Stroke); switch (StrokeType) { case StrokeType.Dashed: paint.SetPathEffect(new DashPathEffect(new[] { 6 * _dm, 2 * _dm }, 0)); break; case StrokeType.Dotted: paint.SetPathEffect(new DashPathEffect(new[] { dAdjustedThicnkess, dAdjustedThicnkess }, 0)); break; } var thicknessOffset = (dAdjustedThicnkess) / 2.0f; var p = new Path(); if (Orientation == SeparatorOrientation.Horizontal) { p.MoveTo(0, thicknessOffset); p.LineTo(r.Width(), thicknessOffset); } else { p.MoveTo(thicknessOffset, 0); p.LineTo(thicknessOffset, r.Height()); } canvas.DrawPath(p, paint); }
public BasicRectangle MeasureText(string text, BasicRectangle rectangle, string fontFace, float fontSize) { var paint = new Paint { AntiAlias = true, TextSize = fontSize * Density }; var rectText = new Rect(); paint.GetTextBounds(text, 0, text.Length, rectText); return new BasicRectangle(rectText.Left, rectText.Top, rectText.Width(), rectText.Height()); }
public void DrawText(Point p, string text, Color fill, string fontFamily = null, double fontSize = 10, double fontWeight = 500, double rotate = 0, HorizontalAlignment halign = HorizontalAlignment.Left, VerticalAlignment valign = VerticalAlignment.Top, Size? maxSize = new Size?()) { using (var paint = new Paint()) { paint.AntiAlias = true; paint.TextSize = (float)fontSize; paint.Color = fill; var bounds = new Rect(); paint.GetTextBounds(text, 0, text.Length, bounds); float dx = 0; if (halign == HorizontalAlignment.Center) { dx = -bounds.Width() / 2; } if (halign == HorizontalAlignment.Right) { dx = -bounds.Width(); } float dy = 0; if (valign == VerticalAlignment.Center) { dy = +bounds.Height() / 2; } if (valign == VerticalAlignment.Top) { dy = bounds.Height(); } canvas.Save(); canvas.Translate(dx, dy); canvas.Rotate((float)rotate); canvas.Translate((float)p.X, (float)p.Y); canvas.DrawText(text, 0, 0, paint); canvas.Restore(); } }
public override void OnDraw(Canvas canvas, Rect bounds) { if (Log.IsLoggable (Tag, LogPriority.Debug)) { Log.Debug (Tag, "onDraw"); } long now = Java.Lang.JavaSystem.CurrentTimeMillis (); time.Set (now); int milliseconds = (int)(now % 1000); int width = bounds.Width (); int height = bounds.Height (); // Draw the background, scaled to fit. if (backgroundScaledBitmap == null || backgroundScaledBitmap.Width != width || backgroundScaledBitmap.Height != height) { backgroundScaledBitmap = Bitmap.CreateScaledBitmap (backgroundBitmap, width, height, true /* filter */); } canvas.DrawColor (Color.Black); canvas.DrawBitmap (backgroundScaledBitmap, 0, 0, null); float centerX = width / 2.0f; float centerY = height / 2.0f; // Draw the ticks. float innerTickRadius = centerX - 10; float outerTickRadius = centerX; for (int tickIndex = 0; tickIndex < 12; tickIndex++) { float tickRot = (float)(tickIndex * Math.PI * 2 / 12); float innerX = (float)Math.Sin (tickRot) * innerTickRadius; float innerY = (float)-Math.Cos (tickRot) * innerTickRadius; float outerX = (float)Math.Sin (tickRot) * outerTickRadius; float outerY = (float)-Math.Cos (tickRot) * outerTickRadius; canvas.DrawLine (centerX + innerX, centerY + innerY, centerX + outerX, centerY + outerY, tickPaint); } float seconds = time.Second + milliseconds / 1000f; float secRot = seconds / 30f * (float)Math.PI; int minutes = time.Minute; float minRot = minutes / 30f * (float)Math.PI; float hrRot = ((time.Hour + (minutes / 60f)) / 6f) * (float)Math.PI; float secLength = centerX - 20; float minLength = centerX - 40; float hrLength = centerX - 80; if (!IsInAmbientMode) { float secX = (float)Math.Sin (secRot) * secLength; float secY = (float)-Math.Cos (secRot) * secLength; canvas.DrawLine (centerX, centerY, centerX + secX, centerY + secY, secondPaint); } float minX = (float)Math.Sin (minRot) * minLength; float minY = (float)-Math.Cos (minRot) * minLength; canvas.DrawLine (centerX, centerY, centerX + minX, centerY + minY, minutePaint); float hrX = (float)Math.Sin (hrRot) * hrLength; float hrY = (float)-Math.Cos (hrRot) * hrLength; canvas.DrawLine (centerX, centerY, centerX + hrX, centerY + hrY, hourPaint); if (IsVisible && !IsInAmbientMode) { Invalidate (); } }
private void DrawLetters(Canvas canvas) { Paint letterPaint = new Paint(); letterPaint.StrokeWidth = 1; letterPaint.SetStyle(Paint.Style.Stroke); int rectWidth = (int)(mViewInfo.Width / 11.0); int rectHeight = (int)(mViewInfo.Height / 11.0); letterPaint.TextSize = Math.Min(rectHeight, 80); for (int i = 0; i < 11; i++) { for (int j = 0; j < 11; j++) { letterPaint.SetStyle(Paint.Style.Stroke); //canvas.DrawRect(new Android.Graphics.Rect(i * rectWidth, j * rectHeight, (i + 1) * rectWidth, (j + 1) * rectHeight), paint); KeyValuePair <int, int> index = new KeyValuePair <int, int>(i, j); if (sSignatureLocations.ContainsKey(index)) { Signature sig = sSignatureLocations[index]; char chr = Arrangement.Layout[sig].Character; char chrToMeasure = chr == ' ' ? 'X' : chr; int x = i * rectWidth; int y = j * rectHeight; Android.Graphics.Rect rect = new Android.Graphics.Rect(x, y, x + rectWidth, y + rectHeight); // The actual character is used for horizontal positioning Android.Graphics.Rect characterBounds = new Android.Graphics.Rect(); letterPaint.GetTextBounds(chrToMeasure.ToString(), 0, 1, characterBounds); // A standard character is used for vertical positioning so all the characters line up Android.Graphics.Rect xBounds = new Android.Graphics.Rect(); letterPaint.GetTextBounds("X", 0, 1, xBounds); // Center the character in the rectangle int textLeft = rect.Left + (int)((rect.Width() - characterBounds.Width()) / 2.0); int textBottom = rect.Bottom - (int)((rect.Height() - xBounds.Width()) / 2.0); // Lift the bottom up away from the border if we're on the bottom row //int textBottom = rect.Bottom - (j == 10 ? 10 : 0); TinyTypeLib.Rect boundsInLocation = new TinyTypeLib.Rect(rect.Left, textBottom - xBounds.Height(), rect.Right, textBottom); if (sig == mViewInfo.CurrentSignature) { // Don't draw within the MiddleSquare canvas.ClipRect(new Android.Graphics.Rect(mViewInfo.Left, mViewInfo.Top, mViewInfo.Right, mViewInfo.Bottom)); Path cp = new Path(); cp.AddCircle(mViewInfo.MiddleSquare.Center.X, mViewInfo.MiddleSquare.Center.Y, mViewInfo.MiddleSquare.Width / 2f, Path.Direction.Cw); canvas.ClipPath(cp, Region.Op.Difference); //canvas.ClipRect(Converter.TinyTypeRectToAndroidRect(mViewInfo.MiddleSquare), Region.Op.Difference); int gradientSize = 20; Paint linePaint = new Paint(); // Draw a line to the circle we're about to draw Line lineToLetter = new Line(mViewInfo.MiddleSquare.Center, boundsInLocation.Center); Line perpendicular = lineToLetter.GetPerpendicular(gradientSize); Color color = GetPositionColor((Position)mViewInfo.CurrentSignature.StartHeading.Quadrant); Color transparent = AndroidUtil.GetTransparentColor(color); linePaint.SetShader(new LinearGradient(perpendicular.Start.X, perpendicular.Start.Y, perpendicular.End.X, perpendicular.End.Y, color, transparent, Shader.TileMode.Mirror)); linePaint.SetStyle(Paint.Style.Stroke); linePaint.StrokeWidth = gradientSize * 2; linePaint.StrokeCap = Paint.Cap.Round; canvas.DrawLine(lineToLetter.Start.X, lineToLetter.Start.Y, lineToLetter.End.X, lineToLetter.End.Y, linePaint); } else { //letterPaint.Color = new Color(255, 0, 255); } if (chr != char.MinValue) { // Fill a circle in the background of the circle Paint letterBackgroundPaint = new Paint(); Color letterBackgroundColor = GetPositionColor((Position)sig.StartQuadrant); Color letterBackgroundTransparent = AndroidUtil.GetTransparentColor(letterBackgroundColor); float radius = Math.Max(boundsInLocation.Width, boundsInLocation.Height) / 2f; letterBackgroundPaint.SetShader(new RadialGradient(boundsInLocation.Center.X, boundsInLocation.Center.Y, radius, letterBackgroundColor, letterBackgroundTransparent, Shader.TileMode.Mirror)); letterBackgroundPaint.SetStyle(Paint.Style.FillAndStroke); canvas.DrawCircle(boundsInLocation.Center.X, boundsInLocation.Center.Y, (float)(Math.Max(boundsInLocation.Width, boundsInLocation.Height) / 2.0), letterBackgroundPaint); letterPaint.SetStyle(Paint.Style.FillAndStroke); canvas.DrawText(chr.ToString(), textLeft, textBottom, letterPaint); } } } } letterPaint.SetStyle(Paint.Style.FillAndStroke); letterPaint.Color = GetPositionColor(Position.Middle); letterPaint.TextSize = mViewInfo.MiddleSquare.Height * 0.75f; Drawing.ClearClip(canvas, mViewInfo); // Draw the selected character in the middle of the square if (mViewInfo.CurrentSignature.Gesture == Signature.Gestures.Normal) { char chr = Arrangement.Layout[mViewInfo.CurrentSignature].Character; // Center the character in the rectangle Android.Graphics.Rect bounds = new Android.Graphics.Rect(); letterPaint.GetTextBounds(chr.ToString(), 0, 1, bounds); int textLeft = mViewInfo.MiddleSquare.Left + (int)((mViewInfo.MiddleSquare.Width - bounds.Width()) / 2.0); int textBottom = mViewInfo.MiddleSquare.Bottom - (int)((mViewInfo.MiddleSquare.Height - bounds.Height()) / 2.0); canvas.DrawText(chr.ToString(), textLeft, textBottom, letterPaint); } /* * // Draw the previous character above the center square * if (mPreviousCharacter != char.MinValue) * { * TinyTypeLib.Rect rect = mViewInfo.MiddleSquare.Offset(0, -mViewInfo.MiddleSquare.Height); * * //paint.SetStyle(Paint.Style.Stroke); * //canvas.DrawRect(Converter.TinyTypeRectToAndroidRect(rect), paint); * //paint.SetStyle(Paint.Style.FillAndStroke); * * // Center the character in the rectangle * Android.Graphics.Rect bounds = new Android.Graphics.Rect(); * letterPaint.GetTextBounds(mPreviousCharacter.ToString(), 0, 1, bounds); * * int textLeft = rect.Left + (int)((rect.Width - bounds.Width()) / 2.0); * int textBottom = rect.Bottom - (int)((rect.Height - bounds.Height()) / 2.0); * * canvas.DrawText(mPreviousCharacter.ToString(), textLeft, textBottom, letterPaint); * }*/ }
//Actual Draw of analogue niddle in Canvas which will show in watch surface public override void OnDraw(Canvas canvas, Rect bounds) { time.SetToNow (); int width = bounds.Width (); int height = bounds.Height (); // Draw the background, scaled to fit. if (backgroundScaledBitmap == null || backgroundScaledBitmap.Width != width || backgroundScaledBitmap.Height != height) { backgroundScaledBitmap = Bitmap.CreateScaledBitmap (backgroundBitmap, width, height, true /* filter */); } canvas.DrawColor (Color.Black); canvas.DrawBitmap (backgroundScaledBitmap, 0, 0, null); float centerX = width / 2.0f; float centerY = height / 2.0f; // Draw the ticks. float innerTickRadius = centerX - 10; float outerTickRadius = centerX; for (int tickIndex = 0; tickIndex < 12; tickIndex++) { float tickRot = (float)(tickIndex * Math.PI * 2 / 12); float innerX = (float)Math.Sin (tickRot) * innerTickRadius; float innerY = (float)-Math.Cos (tickRot) * innerTickRadius; float outerX = (float)Math.Sin (tickRot) * outerTickRadius; float outerY = (float)-Math.Cos (tickRot) * outerTickRadius; canvas.DrawLine (centerX + innerX, centerY + innerY, centerX + outerX, centerY + outerY, tickPaint); } float secRot = time.Second / 30f * (float)Math.PI; int minutes = time.Minute; float minRot = minutes / 30f * (float)Math.PI; float hrRot = ((time.Hour + (minutes / 60f)) / 6f) * (float)Math.PI; float secLength = centerX - 20; float minLength = centerX - 40; float hrLength = centerX - 80; if (!IsInAmbientMode) { float secX = (float)Math.Sin (secRot) * secLength; float secY = (float)-Math.Cos (secRot) * secLength; canvas.DrawLine (centerX, centerY, centerX + secX, centerY + secY, secondPaint); } float minX = (float)Math.Sin (minRot) * minLength; float minY = (float)-Math.Cos (minRot) * minLength; canvas.DrawLine (centerX, centerY, centerX + minX, centerY + minY, minutePaint); float hrX = (float)Math.Sin (hrRot) * hrLength; float hrY = (float)-Math.Cos (hrRot) * hrLength; canvas.DrawLine (centerX, centerY, centerX + hrX, centerY + hrY, hourPaint); }
public Rect GetFramingRect() { if (framingRect == null) { if (camera == null) return null; } if (screenResolution == Size.Empty) return null; int width = screenResolution.Width * 15 / 16; if (width < MIN_FRAME_WIDTH) width = MIN_FRAME_WIDTH; else if (width > MAX_FRAME_WIDTH) width = MAX_FRAME_WIDTH; int height = screenResolution.Height * 4/ 10; if (height < MIN_FRAME_HEIGHT) height = MIN_FRAME_HEIGHT; else if (height > MAX_FRAME_HEIGHT) height = MAX_FRAME_HEIGHT; int leftOffset = (screenResolution.Width - width) / 2; int topOffset = (screenResolution.Height - height) / 2; framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height); Android.Util.Log.Debug("ZXING", "Framing Rect: X=" + framingRect.Left + " Y=" + framingRect.Top + " W=" + framingRect.Width() + " H=" + framingRect.Height()); return framingRect; }
public override void Draw(Android.Graphics.Canvas canvas) { canvas.DrawCircle (mainCenter, mainCenter + 2, radius + radiusBorder, shadowPaint); canvas.DrawCircle (mainCenter, mainCenter, radius + radiusBorder, darkerBackPaint); canvas.DrawCircle (mainCenter, mainCenter, radius, backPaint); canvas.DrawBitmap (icon, mainCenter - icon.Width / 2, mainCenter - icon.Height / 2, imgPaint); if (Count != 0) { int bubbleCenter = center - removeRadius - bubbleOffset; greenPaint.Alpha = redPaint.Alpha = currentBubbleTransparency; removePaint.Alpha = 255 - currentBubbleTransparency; canvas.DrawCircle (bubbleCenter, bubbleCenter, removeRadius, removePaint); canvas.DrawCircle (bubbleCenter, bubbleCenter, innerRadius, Count < 0 ? redPaint : greenPaint); var c = Math.Abs (Count).ToString (); var textBounds = new Rect (); removePaint.GetTextBounds (c, 0, c.Length, textBounds); canvas.DrawText (c, bubbleCenter, bubbleCenter + textBounds.Height () / 2, removePaint); } DrawingCacheEnabled = true; }