当前位置: 首页>>代码示例>>C#>>正文


C# RectF.Width方法代码示例

本文整理汇总了C#中Android.Graphics.RectF.Width方法的典型用法代码示例。如果您正苦于以下问题:C# RectF.Width方法的具体用法?C# RectF.Width怎么用?C# RectF.Width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Graphics.RectF的用法示例。


在下文中一共展示了RectF.Width方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Draw

        public override void Draw(Android.Graphics.Canvas canvas)
        {
            base.Draw(canvas);

            var rect = new RectF(0,0,300,300);
            switch (TheShape)
            {
                case Shape.Circle:
                    canvas.DrawOval(rect, new Paint() { Color = Color.Aqua });
                    break;
                case Shape.Square:
                    canvas.DrawRect(rect, new Paint() { Color = Color.Red });
                    break;
                case Shape.Triangle:
                    var path = new Path();
                    path.MoveTo(rect.CenterX(), 0);
                    path.LineTo(0, rect.Height());
                    path.LineTo(rect.Width(), rect.Height());
                    path.Close();

                    var paint = new Paint() {Color = Color.Magenta};
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawPath(path, paint);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:KiranKumarAlugonda,项目名称:NPlus1DaysOfMvvmCross,代码行数:29,代码来源:CustomDrawShapeView.cs

示例2: Transition

    public Transition(RectF srcRect, RectF dstRect, long duration, IInterpolator interpolator) {
        if (!MathUtils.HaveSameAspectRatio(srcRect, dstRect)) {
            throw new IncompatibleRatioException();
        }
        _mSrcRect = srcRect;
        _mDstRect = dstRect;
        _mDuration = duration;
        _mInterpolator = interpolator;

        // Precomputes a few variables to avoid doing it in onDraw().
        _mWidthDiff = dstRect.Width() - srcRect.Width();
        _mHeightDiff = dstRect.Height() - srcRect.Height();
        _mCenterXDiff = dstRect.CenterX() - srcRect.CenterX();
        _mCenterYDiff = dstRect.CenterY() - srcRect.CenterY();
    }
开发者ID:Julien-Mialon,项目名称:MaterialViewPager.Xamarin,代码行数:15,代码来源:Transition.cs

示例3: GetImage

		Bitmap GetImage (Color strokeColor, Color fillColor, System.Drawing.SizeF size, float scale, 
		                 bool shouldCrop = true, bool keepAspectRatio = true)
		{
			if (size.Width == 0 || size.Height == 0 || scale <= 0)
				return null;

			float uncroppedScale;
			RectF croppedRectangle = new RectF ();

			System.Drawing.PointF [] cachedPoints;

			if (shouldCrop && (cachedPoints = Points).Any ()) {
				croppedRectangle = getCroppedRectangle (cachedPoints);

				if (croppedRectangle.Left >= 5)
					croppedRectangle.Left -= 5;
				if (croppedRectangle.Right <= size.Width - 5)
					croppedRectangle.Right += 5;
				if (croppedRectangle.Top >= 5)
					croppedRectangle.Top -= 5;
				if (croppedRectangle.Bottom <= size.Height - 5)
					croppedRectangle.Bottom += 5;

				float scaleX = (croppedRectangle.Right - croppedRectangle.Left) / Width;
				float scaleY = (croppedRectangle.Bottom - croppedRectangle.Top) / Height;
				uncroppedScale = 1 / Math.Max (scaleX, scaleY);
			} else {
				uncroppedScale = scale;
			}

			Bitmap image;
			if (keepAspectRatio)
				image = Bitmap.CreateBitmap ((int)size.Width, (int)size.Height, 
					Bitmap.Config.Argb8888);
			else
				image = Bitmap.CreateBitmap ((int)(croppedRectangle.Width () * uncroppedScale), (int)(croppedRectangle.Height () * uncroppedScale),
					Bitmap.Config.Argb8888);
			Canvas canvas = new Canvas (image);
			canvas.Scale (uncroppedScale, uncroppedScale);

			DrawStrokesOnCanvas (canvas, strokeColor, fillColor, shouldCrop, croppedRectangle);

			return image;
		}
开发者ID:ronrat,项目名称:SignaturePad,代码行数:44,代码来源:SignaturePadView.cs

示例4: growBy

        // Grows the cropping rectange by (dx, dy) in image space.
        private void growBy(float dx, float dy)
        {
            if (maintainAspectRatio)
            {
                if (dx != 0)
                {
                    dy = dx / initialAspectRatio;
                }
                else if (dy != 0)
                {
                    dx = dy * initialAspectRatio;
                }
            }

            // Don't let the cropping rectangle grow too fast.
            // Grow at most half of the difference between the image rectangle and
            // the cropping rectangle.
            RectF r = new RectF(cropRect);
            if (dx > 0F && r.Width() + 2 * dx > imageRect.Width())
            {
                float adjustment = (imageRect.Width() - r.Width()) / 2F;
                dx = adjustment;
                if (maintainAspectRatio)
                {
                    dy = dx / initialAspectRatio;
                }
            }
            if (dy > 0F && r.Height() + 2 * dy > imageRect.Height())
            {
                float adjustment = (imageRect.Height() - r.Height()) / 2F;
                dy = adjustment;
                if (maintainAspectRatio)
                {
                    dx = dy * initialAspectRatio;
                }
            }

            r.Inset(-dx, -dy);

            // Don't let the cropping rectangle shrink too fast.
            float widthCap = 25F;
            if (r.Width() < widthCap)
            {
                r.Inset(-(widthCap - r.Width()) / 2F, 0F);
            }
            float heightCap = maintainAspectRatio
                ? (widthCap / initialAspectRatio)
                    : widthCap;
            if (r.Height() < heightCap)
            {
                r.Inset(0F, -(heightCap - r.Height()) / 2F);
            }

            // Put the cropping rectangle inside the image rectangle.
            if (r.Left < imageRect.Left)
            {
                r.Offset(imageRect.Left - r.Left, 0F);
            }
            else if (r.Right > imageRect.Right)
            {
                r.Offset(-(r.Right - imageRect.Right), 0);
            }
            if (r.Top < imageRect.Top)
            {
                r.Offset(0F, imageRect.Top - r.Top);
            }
            else if (r.Bottom > imageRect.Bottom)
            {
                r.Offset(0F, -(r.Bottom - imageRect.Bottom));
            }

            cropRect.Set(r);
            DrawRect = computeLayout();
            context.Invalidate();
        }
开发者ID:kevinrood,项目名称:cropimage-xamarin,代码行数:76,代码来源:HighlightView.cs

示例5: Setup

        public void Setup(Matrix m, Rect imageRect, RectF cropRect, bool maintainAspectRatio)
        {
            matrix = new Matrix(m);

            this.cropRect = cropRect;
            this.imageRect = new RectF(imageRect);
            this.maintainAspectRatio = maintainAspectRatio;

            initialAspectRatio = cropRect.Width() / cropRect.Height();
            DrawRect = computeLayout();

            focusPaint.SetARGB(125, 50, 50, 50);
            noFocusPaint.SetARGB(125, 50, 50, 50);
            outlinePaint.StrokeWidth = 3;
            outlinePaint.SetStyle(Paint.Style.Stroke);
            outlinePaint.AntiAlias = true;

            mode = ModifyMode.None;
            init();
        }
开发者ID:kevinrood,项目名称:cropimage-xamarin,代码行数:20,代码来源:HighlightView.cs

示例6: GetRectRatio

		internal static float GetRectRatio(RectF rect)
		{
			return rect.Width() / rect.Height();
		}
开发者ID:Julien-Mialon,项目名称:MaterialViewPager.Xamarin,代码行数:4,代码来源:MathUtils.cs

示例7: InitializeImages

        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;
//.........这里部分代码省略.........
开发者ID:lea-and-anthony,项目名称:Tetrim,代码行数:101,代码来源:ButtonStroked.cs

示例8: GenerateRandomRect

		/**
		 * Generates a random rect that can be fully contained within {@code drawableBounds} and
		 * has the same aspect ratio of {@code viewportRect}. The dimensions of this random rect
		 * won't be higher than the largest rect with the same aspect ratio of {@code viewportRect}
		 * that {@code drawableBounds} can contain. They also won't be lower than the dimensions
		 * of this upper rect limit weighted by {@code MIN_RECT_FACTOR}.
		 * @param drawableBounds the bounds of the drawable that will be zoomed and panned.
		 * @param viewportRect the bounds of the view that the drawable will be shown.
		 * @return an arbitrary generated rect with the same aspect ratio of {@code viewportRect}
		 * that will be contained within {@code drawableBounds}.
		 */
		private RectF GenerateRandomRect(RectF drawableBounds, RectF viewportRect)
		{
			float drawableRatio = MathUtils.GetRectRatio(drawableBounds);
			float viewportRectRatio = MathUtils.GetRectRatio(viewportRect);
			RectF maxCrop;

			if (drawableRatio > viewportRectRatio)
			{
				float r = (drawableBounds.Height() / viewportRect.Height()) * viewportRect.Width();
				float b = drawableBounds.Height();
				maxCrop = new RectF(0, 0, r, b);
			}
			else
			{
				float r = drawableBounds.Width();
				float b = (drawableBounds.Width() / viewportRect.Width()) * viewportRect.Height();
				maxCrop = new RectF(0, 0, r, b);
			}

			float randomFloat = MathUtils.Truncate((float)_mRandom.NextDouble(), 2);
			float factor = MIN_RECT_FACTOR + ((1 - MIN_RECT_FACTOR) * randomFloat);

			float width = factor * maxCrop.Width();
			float height = factor * maxCrop.Height();
			int widthDiff = (int)(drawableBounds.Width() - width);
			int heightDiff = (int)(drawableBounds.Height() - height);
			int left = widthDiff > 0 ? _mRandom.Next(widthDiff) : 0;
			int top = heightDiff > 0 ? _mRandom.Next(heightDiff) : 0;
			return new RectF(left, top, left + width, top + height);
		}
开发者ID:Julien-Mialon,项目名称:MaterialViewPager.Xamarin,代码行数:41,代码来源:RandomTransitionGenerator.cs

示例9: OnSizeChanged

		protected override void OnSizeChanged (int w, int h, int oldW, int oldH)
		{	
			HEIGHT = h;
			WIDTH = w;

			HALF_WIDTH = (int)Math.Round ((Double)w / 2);
			HALF_HEIGHT = (int)(Math.Round ((Double)h / 2));

			//int OFFSET = mCenterOval.Width () / 3.0f;

			mCenterOval = new RectF ();
			//float OFFSET = 140f;
			//Change the OFFSET to relative value according to the screen width
			float OFFSET = WIDTH / 5;
			//mCenterOval.Set (OFFSET, OFFSET, WIDTH - OFFSET, WIDTH - OFFSET);
			//move the mCenterOval a little bit up
			mCenterOval.Set (OFFSET, OFFSET * (float)0.5, WIDTH - OFFSET, WIDTH - (float)1.5 * OFFSET);

			mCx = (int)Math.Round (mCenterOval.CenterX ());
			mCy = (int)Math.Round (mCenterOval.CenterY ());
			mRadius = (int)Math.Round (mCenterOval.Width () / 2.0f);

			mInnerCircleRadius = mRadius - (mPaint.StrokeWidth * 0.9f);

			updateCircleCoordinate (mCx, 0);
		}
开发者ID:KiranKumarAlugonda,项目名称:TXTSHD,代码行数:26,代码来源:ChartView.cs

示例10: Center

        /// <summary>
        /// Center as much as possible in one or both axis.  Centering is
        /// defined as follows:  if the image is scaled down below the
        /// view's dimensions then center it (literally).  If the image
        /// is scaled larger than the view and is translated out of view
        /// then translate it back into view (i.e. eliminate black bars).
        /// </summary>
        protected void Center(bool horizontal, bool vertical)
        {
            //return;
            if (bitmapDisplayed.Bitmap == null)
            {
                return;
            }

            Matrix m = GetImageViewMatrix();

            RectF rect = new RectF(0, 0,
                                   bitmapDisplayed.Bitmap.Width,
                                   bitmapDisplayed.Bitmap.Height);

            m.MapRect(rect);

            float height = rect.Height();
            float width = rect.Width();

            float deltaX = 0, deltaY = 0;

            if (vertical)
            {
                int viewHeight = Height;
                if (height < viewHeight)
                {
                    deltaY = (viewHeight - height) / 2 - rect.Top;
                }
                else if (rect.Top > 0)
                {
                    deltaY = -rect.Top;
                }
                else if (rect.Bottom < viewHeight)
                {
                    deltaY = Height - rect.Bottom;
                }
            }

            if (horizontal)
            {
                int viewWidth = _width; //Width;
                if (width < viewWidth)
                {
                    deltaX = (viewWidth - width) / 2 - rect.Left;
                }
                else if (rect.Left > 0)
                {
                    deltaX = -rect.Left;
                }
                else if (rect.Right < viewWidth)
                {
                    deltaX = viewWidth - rect.Right;
                }
            }

            PostTranslate(deltaX, deltaY);
            ImageMatrix = GetImageViewMatrix();
        }
开发者ID:nielscup,项目名称:ImageCrop,代码行数:65,代码来源:ImageViewTouchBase.cs

示例11: Draw

		public override void Draw (Canvas canvas)
		{
			base.Draw (canvas);

			if (!scaled) {

				density = Resources.DisplayMetrics.Density;

				padding *= density;

				lineWidth *= density;

				fontSize *= density;

				scaled = true;
			}


			_highTemps = null;
			_lowTemps = null;

			_hourlyTemps = null;


			if (Forecasts.Count == 0 || Hourly.Count == 0) return;


			graphRect = new RectF (padding, padding, canvas.Width - padding, canvas.Height - padding);// CGRect (rect.X + padding, rect.Y + padding, rect.Width - (padding * 2), rect.Height - (padding * 2));

			var days = Hourly.GroupBy (h => h.FCTTIME.mday).Select (g => g.First ().FCTTIME.weekday_name_abbrev).ToList ();

			var dayCount = hourly ? days.Count : Forecasts.Count;


			var xAxisScale = (graphRect.Width () + padding / 2) / dayCount;

			inset = xAxisScale / 2;


			var highest = (float)(hourly ? HourlyTemps.Max () : HighTemps.Max ());
			var lowest = (float)(hourly ? HourlyTemps.Min () : LowTemps.Min ());


			scaleHigh = (float)Math.Round (highest, MidpointRounding.AwayFromZero);
			scaleLow = lowest < 0 ? (float)Math.Round (lowest, MidpointRounding.AwayFromZero) : (float)Math.Round (lowest);

			var rangePadding = Settings.UomTemperature.IsImperial () ? scalePadding : (scalePadding / 2);


			scaleHigh += rangePadding;
			scaleLow -= rangePadding;

			scaleRange = scaleHigh - scaleLow;


			var scaleIncrement = scaleRange / dividerCount;

			scaleX = (graphRect.Width () - inset) / (hourly ? HourlyTemps.Count : Forecasts.Count);
			scaleY = graphRect.Height () / dividerCount;


			float x, y;

			var white = Color.White;


			// Draw x and y axis
			var paint = new Paint ();
			paint.Color = white;
			paint.StrokeWidth = 1;

			using (Path path = new Path ()) {

				path.MoveTo (graphRect.Left, graphRect.Top);

				path.LineTo (graphRect.Left, graphRect.Bottom);
				path.LineTo (graphRect.Right, graphRect.Bottom);

				paint.SetStyle (Paint.Style.Stroke);

				canvas.DrawPath (path, paint);
			}


			Color translucentBlack = Color.Argb (20, 0, 0, 0);

			paint.Color = translucentBlack;

			paint.SetStyle (Paint.Style.Fill);

			// Draw horizontal gridlines
			for (int i = 1; i < dividerCount; i += 2) {

				y = graphRect.Bottom - ((i + 1) * scaleY);

				using (RectF grid = new RectF (padding, y, graphRect.Right, y + scaleY))
					canvas.DrawRect (grid, paint);
			}


//.........这里部分代码省略.........
开发者ID:colbylwilliams,项目名称:XWeather,代码行数:101,代码来源:DailyGraphView.cs

示例12: GetImage

		Bitmap GetImage (Color strokeColor, Color fillColor, System.Drawing.SizeF size, float scale, 
		                 bool shouldCrop = true)
		{
			if (size.Width == 0 || size.Height == 0 || scale <= 0)
				return null;

			float uncroppedScale;
			System.Drawing.SizeF uncroppedSize;
			RectF croppedRectangle;

			if (shouldCrop && Points.Count () != 0) {
				croppedRectangle = getCroppedRectangle ();
				float scaleX = (croppedRectangle.Right - croppedRectangle.Left) / Width;
				float scaleY = (croppedRectangle.Bottom - croppedRectangle.Top) / Height;
				uncroppedScale = 1 / Math.Max (scaleX, scaleY);
				//uncroppedScale = 1 / getScaleFromSize (croppedRectangle.Size, Bounds);
				uncroppedSize = getSizeFromScale (uncroppedScale, size.Width, size.Height);
			} else {
				uncroppedScale = scale;
				uncroppedSize = size;
			}

			Bitmap image = Bitmap.CreateBitmap ((int)uncroppedSize.Width, (int)uncroppedSize.Height, 
			                                    Bitmap.Config.Argb8888);
			Canvas canvas = new Canvas (image);
			canvas.Scale (uncroppedScale, uncroppedScale);

			DrawStrokesOnCanvas (canvas, strokeColor, fillColor);
	
			if (shouldCrop && Points.Count () != 0) {
				croppedRectangle = getCroppedRectangle ();
				RectF scaledRectangle = new RectF (croppedRectangle.Left * uncroppedScale,
				                                   croppedRectangle.Top * uncroppedScale,
				                                   croppedRectangle.Right * uncroppedScale,
				                                   croppedRectangle.Bottom * uncroppedScale);

				if (scaledRectangle.Left >= 5)
					scaledRectangle.Left -= 5;
				if (scaledRectangle.Right <= uncroppedSize.Width - 5)
					scaledRectangle.Right += 5;
				if (scaledRectangle.Top >= 5)
					scaledRectangle.Top -= 5;
				if (scaledRectangle.Bottom <= uncroppedSize.Height - 5)
					scaledRectangle.Bottom += 5;
				image = Bitmap.CreateBitmap (image, 
				                             (int) scaledRectangle.Left, 
				                             (int) scaledRectangle.Top,
				                             (int) scaledRectangle.Width (),
				                             (int) scaledRectangle.Height ());
			}
			return image;
		}
开发者ID:rrawla,项目名称:SignaturePad,代码行数:52,代码来源:SignaturePadView.cs


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