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


C# Rect.Inset方法代码示例

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


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

示例1: moveBy

        // 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);
        }
开发者ID:kevinrood,项目名称:cropimage-xamarin,代码行数:21,代码来源:HighlightView.cs

示例2: onSaveClicked

        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);
            }
        }
开发者ID:kevinrood,项目名称:cropimage-xamarin,代码行数:86,代码来源:CropImage.cs

示例3: Crop

        /// <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;
        }
开发者ID:nielscup,项目名称:ImageCrop,代码行数:86,代码来源:ImageCropView.cs

示例4: OnDraw

		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);
		}
开发者ID:jeedey93,项目名称:xamarin-android-samples,代码行数:18,代码来源:FlabbyLayout.cs


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