• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Graphics.Rect类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Android.Graphics.Rect的典型用法代码示例。如果您正苦于以下问题:C# Rect类的具体用法?C# Rect怎么用?C# Rect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Rect类属于Android.Graphics命名空间,在下文中一共展示了Rect类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetBitmapMarker

        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;
        }
开发者ID:sgraphics,项目名称:BindableMapTest,代码行数:30,代码来源:ExtendedMapRenderer.cs


示例2: MeasureString

		//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);
		}
开发者ID:tzachshabtay,项目名称:MonoAGS,代码行数:28,代码来源:AndroidFont.cs


示例3: GetRoundedCornerBitmap

		// If you would like to create a circle of the image set pixels to half the width of the image.
		internal static   Bitmap GetRoundedCornerBitmap(Bitmap bitmap, int pixels)
		{
			Bitmap output = null;

			try
			{
				output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
				Canvas canvas = new Canvas(output);

				Color color = new Color(66, 66, 66);
				Paint paint = new Paint();
				Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
				RectF rectF = new RectF(rect);
				float roundPx = pixels;

				paint.AntiAlias = true;
				canvas.DrawARGB(0, 0, 0, 0);
				paint.Color = color;
				canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);

				paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
				canvas.DrawBitmap(bitmap, rect, rect, paint);
			}
			catch (System.Exception err)
			{
				System.Console.WriteLine ("GetRoundedCornerBitmap Error - " + err.Message);
			}

			return output;
		}
开发者ID:suchithm,项目名称:SampleImageBitMap,代码行数:31,代码来源:ImageHelper.cs


示例4: GetItemOffsets

 public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
 {
     if (parent.GetChildLayoutPosition(view) != 0)
     {
         outRect.Top = space;
     }
 }
开发者ID:nepula-h-okuyama,项目名称:DroidKaigi2016Xamarin,代码行数:7,代码来源:SpaceItemDecoration.cs


示例5: getRoundedCroppedBitmap

		public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
			Bitmap finalBitmap;
			if (bitmap.Width != radius || bitmap.Height!= radius)
				finalBitmap = Bitmap.CreateScaledBitmap(bitmap, radius, radius,
					false);
			else
				finalBitmap = bitmap;
			Bitmap output = Bitmap.CreateBitmap(finalBitmap.Width,
				finalBitmap.Height, Bitmap.Config.Argb8888);
			Canvas canvas = new Canvas(output);

			 Paint paint = new Paint();
			Rect rect = new Rect(0, 0, finalBitmap.Width,
				finalBitmap.Height);

			paint.AntiAlias=true;
			paint.FilterBitmap=true;
			paint.Dither=true;
			canvas.DrawARGB(0, 0, 0, 0);
			paint.Color=Color.ParseColor("#BAB399");
			canvas.DrawCircle(finalBitmap.Width / 2 + 0.7f,
				finalBitmap.Height / 2 + 0.7f,
				finalBitmap.Width / 2 + 0.1f, paint);
			paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
			canvas.DrawBitmap(finalBitmap, rect, rect, paint);

			return output;
		}	
开发者ID:IanLeatherbury,项目名称:tryfsharpforms,代码行数:28,代码来源:RoundedImageView.cs


示例6: Run

        public void Run()
        {
            Rect dstRect = new Rect();
            long startTime = Java.Lang.System.NanoTime();
            while (running)
            {
                if (!holder.GetSurface().IsValid())
                    continue;


                float deltaTime = (Java.Lang.System.NanoTime() - startTime) / 10000000.000f;
                startTime = Java.Lang.System.NanoTime();

                if (deltaTime > 3.15)
                {
                    deltaTime = (float)3.15;
                }


                game.getCurrentScreen().update(deltaTime);
                game.getCurrentScreen().paint(deltaTime);



                Canvas canvas = holder.LockCanvas();
                canvas.GetClipBounds(dstRect);
                canvas.DrawBitmap(framebuffer, null, dstRect, null);
                holder.UnlockCanvasAndPost(canvas);


            }
        }
开发者ID:MahendrenGanesan,项目名称:samples,代码行数:32,代码来源:AndroidFastRenderView.cs


示例7: CalculateStartScale

        /// <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;
        }
开发者ID:89sos98,项目名称:monodroid-samples,代码行数:33,代码来源:ZoomActivity.cs


示例8: OnDraw

        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);
            }
        }
开发者ID:GGHG72,项目名称:Xamarin-Forms-Labs,代码行数:32,代码来源:SensorBarDroidView.cs


示例9: GetItemOffsets

 public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
 {
     outRect.Left = left;
     outRect.Top = top;
     outRect.Right = right;
     outRect.Bottom = bottom;
 }
开发者ID:huguodong,项目名称:SwipeMenuRecyclerView,代码行数:7,代码来源:StaggeredSpaceItemDecoration.cs


示例10: OnFocusChanged

 protected override void OnFocusChanged(bool gainFocus, Android.Views.FocusSearchDirection direction, Rect previouslyFocusedRect)
 {
     if (gainFocus)
     {
         base.OnFocusChanged(true, direction, previouslyFocusedRect);
     }
 }
开发者ID:mcrip2401,项目名称:ActionBar,代码行数:7,代码来源:ScrollingTextView.cs


示例11: GetCroppedBitmap

        static Bitmap GetCroppedBitmap (Bitmap bmp, int radius)
        {
            Bitmap sbmp;
            if (bmp.Width != radius || bmp.Height != radius)
                sbmp = Bitmap.CreateScaledBitmap (bmp, radius, radius, false);
            else
                sbmp = bmp;
            var output = Bitmap.CreateBitmap (sbmp.Width,
                             sbmp.Height, Bitmap.Config.Argb8888);
            var canvas = new Canvas (output);

            var paint = new Paint ();
            var rect = new Rect (0, 0, sbmp.Width, sbmp.Height);

            paint.AntiAlias = true;
            paint.FilterBitmap = true;
            paint.Dither = true;
            canvas.DrawARGB (0, 0, 0, 0);
            paint.Color = Color.ParseColor ("#BAB399");
            canvas.DrawCircle (sbmp.Width / 2 + 0.7f, sbmp.Height / 2 + 0.7f,
                sbmp.Width / 2 + 0.1f, paint);
            paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcIn));
            canvas.DrawBitmap (sbmp, rect, rect, paint);

            return output;
        }
开发者ID:vgvassilev,项目名称:couchbase-connect-14,代码行数:26,代码来源:RoundedImageView.cs


示例12: LinedEditText

		// we need this constructor for LayoutInflater
		public LinedEditText (Context context, IAttributeSet attrs)
			: base (context, attrs)
		{
			rect = new Rect ();
			paint = new Paint ();
			paint.SetStyle (Android.Graphics.Paint.Style.Stroke);
			paint.Color = Color.LightGray;
		}
开发者ID:CHANDAN145,项目名称:monodroid-samples,代码行数:9,代码来源:LinedEditText.cs


示例13: BitmapDrawable

 public BitmapDrawable(Resources resources, int id, double left, double top, double right, double bottom)
 {
     mBitmap = BitmapFactory.DecodeResource(resources, id, new BitmapFactory.Options {
         InDither = false,
         InPreferredConfig = Bitmap.Config.Argb8888
     });
     mBounds = new Rect((int)left, (int)top, (int)right, (int)bottom);
 }
开发者ID:harrisse,项目名称:Lotus,代码行数:8,代码来源:BitmapDrawable.cs


示例14: CanvasRenderContext

 /// <summary>
 /// Initializes a new instance of the <see cref="CanvasRenderContext" /> class.
 /// </summary>
 /// <param name="scale">The scale.</param>
 public CanvasRenderContext(double scale)
 {
     this.paint = new Paint();
     this.path = new Path();
     this.bounds = new Rect();
     this.pts = new List<float>();
     this.Scale = scale;
 }
开发者ID:Cheesebaron,项目名称:oxyplot,代码行数:12,代码来源:CanvasRenderContext.cs


示例15: OnBoundsChange

		protected override void OnBoundsChange (Rect bounds)
		{
			base.OnBoundsChange (bounds);
			if (oval == null)
				return;
			
			oval.Set (0, 0, bounds.Width (), bounds.Height ());
		}
开发者ID:richardboegli,项目名称:KinderChat,代码行数:8,代码来源:CircleDrawable.cs


示例16: GetItemOffsets

 public override void GetItemOffsets (Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
 {
     if (orientation == VerticalList) {
         outRect.Set (0, 0, 0, divider.IntrinsicHeight);
     } else {
         outRect.Set (0, 0, divider.IntrinsicWidth, 0);
     }
 }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:8,代码来源:DividerItemDecoration.cs


示例17: IsHit

		/// <summary>
		/// Determines whether the specified point is hit.
		/// </summary>
		/// <param name="view">The view.</param>
		/// <param name="point">The point.</param>
		/// <returns><c>true</c> if the specified point is hit; otherwise, <c>false</c>.</returns>
		public static bool IsHit(this Android.Views.View view, PointF point)
        {
            var r = new Rect();
            view.GetHitRect(r);

            var touch = new Rect((int)point.X, (int)point.Y, (int)point.X, (int)point.Y);

            return r.Intersect(touch);
        }
开发者ID:nSolvePR,项目名称:Xamarin-Forms-Labs,代码行数:15,代码来源:ViewExtensions.cs


示例18: Collider

        public Collider(int leftOffset, int rightOffset, int topOffset, int bottomOffset)
        {
            this.leftOffset = leftOffset;
            this.rightOffset = rightOffset;
            this.topOffset = topOffset;
            this.bottomOffset = bottomOffset;

            Boundary = new Rect (0, 0, 0, 0);
        }
开发者ID:Paludan,项目名称:BeerRun,代码行数:9,代码来源:Collider.cs


示例19: Projectile

        public Projectile(int x, int y)
        {
            _x = x + xOFFSET;
            _y = y + yOFFSET;
            _speedX = 7;
            _visible = true;

            boundary = new Rect ();
        }
开发者ID:Paludan,项目名称:BeerRun,代码行数:9,代码来源:Projectile.cs


示例20: Projectile

        public Projectile(int startX, int startY)
        {
            x = startX;
            y = startY;
            speedX = 7;
            visible = true;

            r = new Rect(0, 0, 0, 0);
        }
开发者ID:MahendrenGanesan,项目名称:samples,代码行数:9,代码来源:Projectile.cs



注:本文中的Android.Graphics.Rect类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Graphics.RectF类代码示例发布时间:2022-05-24
下一篇:
C# Graphics.Path类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap