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


C# UIImage.Draw方法代码示例

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


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

示例1: RoundCorners

        public static UIImage RoundCorners (UIImage image, int radius)
        {
			if (image == null)
				throw new ArgumentNullException ("image");
			
			UIImage converted = image;
			
			image.InvokeOnMainThread(() => {
	            UIGraphics.BeginImageContext (image.Size);
				float imgWidth = image.Size.Width;
				float imgHeight = image.Size.Height;
	
	            var c = UIGraphics.GetCurrentContext ();
	
	            c.BeginPath ();
	            c.MoveTo (imgWidth, imgHeight/2);
	            c.AddArcToPoint (imgWidth, imgHeight, imgWidth/2, imgHeight, radius);
	            c.AddArcToPoint (0, imgHeight, 0, imgHeight/2, radius);
	            c.AddArcToPoint (0, 0, imgWidth/2, 0, radius);
	            c.AddArcToPoint (imgWidth, 0, imgWidth, imgHeight/2, radius);
	            c.ClosePath ();
	            c.Clip ();
	
	            image.Draw (new PointF (0, 0));
	            converted = UIGraphics.GetImageFromCurrentImageContext ();
	            UIGraphics.EndImageContext ();
			});
			
            return converted;
        }
开发者ID:Redth,项目名称:MonoTouch.UrlImageStore,代码行数:30,代码来源:Graphics.cs

示例2: RemoveSharpEdges

        // Child proof the image by rounding the edges of the image
        internal static UIImage RemoveSharpEdges (UIImage image)
        {
			if (image == null)
				throw new ArgumentNullException ("image");
			
            UIGraphics.BeginImageContext (image.Size);
			float imgWidth = image.Size.Width;
			float imgHeight = image.Size.Height;

            var c = UIGraphics.GetCurrentContext ();

            c.BeginPath ();
            c.MoveTo (imgWidth, imgHeight/2);
            c.AddArcToPoint (imgWidth, imgHeight, imgWidth/2, imgHeight, 4);
            c.AddArcToPoint (0, imgHeight, 0, imgHeight/2, 4);
            c.AddArcToPoint (0, 0, imgWidth/2, 0, 4);
            c.AddArcToPoint (imgWidth, 0, imgWidth, imgHeight/2, 4);
            c.ClosePath ();
            c.Clip ();

            image.Draw (new PointF (0, 0));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
开发者ID:azcoov,项目名称:MonoTouch.Dialog.Extensions,代码行数:26,代码来源:Graphics.cs

示例3: ResizeImage

		// resize the image (without trying to maintain aspect ratio)
		UIImage ResizeImage(UIImage sourceImage, float width, float height)
		{
			UIGraphics.BeginImageContext(new SizeF(width, height));
			sourceImage.Draw(new RectangleF(0, 0, width, height));
			var resultImage = UIGraphics.GetImageFromCurrentImageContext();
			UIGraphics.EndImageContext();
			return resultImage;
		}
开发者ID:vgvassilev,项目名称:couchbase-connect-14,代码行数:9,代码来源:ImageResizerService.cs

示例4: Scale

		public static UIImage Scale (UIImage image, SizeF size)
		{
			UIGraphics.BeginImageContext (size);
			image.Draw (new RectangleF (new PointF (0, 0), size));
			var ret = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();
			return ret;
		}		
开发者ID:21Off,项目名称:21Off,代码行数:8,代码来源:GraphicsII.cs

示例5: CopyAndDispose

		public static UIImage CopyAndDispose(UIImage original)
		{
			UIGraphics.BeginImageContextWithOptions(original.Size, false, 0);
			original.Draw(new RectangleF(0, 0, original.Size.Width, original.Size.Height));
			UIImage copy = UIGraphics.GetImageFromCurrentImageContext();
		  	UIGraphics.EndImageContext();	
		    original.Dispose();
			return copy;
		}
开发者ID:modulexcite,项目名称:artapp,代码行数:9,代码来源:ImageHelper.cs

示例6: Stitch

		public static UIImage Stitch(UIImage left, UIImage right)
		{
			UIGraphics.BeginImageContext(new SizeF(left.Size.Width + right.Size.Width, left.Size.Height));
			left.Draw(new RectangleF(0, 0, left.Size.Width,left.Size.Height));
			right.Draw(new RectangleF(left.Size.Width, 0, right.Size.Width, right.Size.Height), CGBlendMode.Normal, 1.0f);
			UIImage stitched = UIGraphics.GetImageFromCurrentImageContext();
			UIGraphics.EndImageContext();			
			return stitched;
		}
开发者ID:modulexcite,项目名称:artapp,代码行数:9,代码来源:ImageHelper.cs

示例7: ResizeImage

		private UIImage ResizeImage (UIImage view)
		{
			UIImage resultImage = null;

			var newSize = new SizeF (view.Size.Width / 2, view.Size.Height / 2);
			UIGraphics.BeginImageContext (newSize);
			view.Draw (new RectangleF (0, 0, newSize.Width, newSize.Height));
			resultImage = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();

			return resultImage;
		}
开发者ID:RangoJT,项目名称:monotouch-samples,代码行数:12,代码来源:ZoomImageView.cs

示例8: CropImage

		// crop the image, without resizing
		UIImage CropImage(UIImage sourceImage, RectangleF rect)
		{
			var imgSize = sourceImage.Size;
			UIGraphics.BeginImageContext(new SizeF(rect.Width, rect.Height));
			var context = UIGraphics.GetCurrentContext();
			var clippedRect = new RectangleF(0, 0, rect.Width, rect.Height);
			context.ClipToRect(clippedRect);
			var drawRect = new RectangleF(-rect.X, -rect.Y, imgSize.Width, imgSize.Height);
			sourceImage.Draw(drawRect);
			var modifiedImage = UIGraphics.GetImageFromCurrentImageContext();
			UIGraphics.EndImageContext();
			return modifiedImage;
		}
开发者ID:vgvassilev,项目名称:couchbase-connect-14,代码行数:14,代码来源:ImageResizerService.cs

示例9: RemoveSharpEdges

		// Child proof the image by rounding the edges of the image
		public static UIImage RemoveSharpEdges (UIImage image)
		{
			if (image == null)
				throw new ArgumentNullException ("image");


			UIGraphics.BeginImageContext (image.Size);
			var c = UIGraphics.GetCurrentContext ();

			c.AddPath (MakeRoundedPath (image.Size.Height));

			image.Draw (new RectangleF (PointF.Empty, image.Size));
			var converted = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();
			return converted;
		}
开发者ID:RobGibbens,项目名称:ArtekSoftware.Codemash,代码行数:17,代码来源:Graphics.cs

示例10: ResizeImageToMaximumSize

        public static UIImage ResizeImageToMaximumSize(UIImage sourceImage, float maxWidth, float maxHeight)
        {
            var sourceSize = sourceImage.Size;
                var maxResizeFactor = Math.Min(maxWidth / sourceSize.Width, maxHeight / sourceSize.Height);

            if (maxResizeFactor > 1)
            {
                return sourceImage;
            }

            var width = maxResizeFactor * sourceSize.Width;
                var height = maxResizeFactor * sourceSize.Height;

            UIGraphics.BeginImageContext(new SizeF(width, height));
                	sourceImage.Draw(new RectangleF(0, 0, width, height));
                	var resultImage = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();

            return resultImage;
        }
开发者ID:ChristianJaspers,项目名称:saapp-ios,代码行数:20,代码来源:ImageManipulationHelper.cs

示例11: RemoveSharpEdges

        // Child proof the image by rounding the edges of the image
        internal static UIImage RemoveSharpEdges(UIImage image)
        {
            if (image == null)
            {
                Console.WriteLine("throwing error at remove sharp edges");
                throw new ArgumentNullException ("image");
            }
            var imageSize = Util.IsIpad ? largeSize : smallSize * UIScreen.MainScreen.Scale;
            UIGraphics.BeginImageContext (new SizeF (imageSize, imageSize));
            var c = UIGraphics.GetCurrentContext ();
            if( Util.IsIpad || UIScreen.MainScreen.Scale == 2f)
            c.AddPath (largePath);
            else
                c.AddPath (smallPath);
            c.Clip ();

            image.Draw (new RectangleF (0, 0, imageSize, imageSize));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
开发者ID:Clancey,项目名称:Facetroids,代码行数:22,代码来源:Graphics.cs

示例12: ResizeImage

        public static UIImage ResizeImage(UIImage theImage,float width, float height, bool keepRatio)
        {
            if(keepRatio)
            {
                var ratio = theImage.Size.Height / theImage.Size.Width;
                if(height >0)
                    width = height * ratio;
                else
                    height = width * ratio;
            }

            UIGraphics.BeginImageContext (new SizeF (width,height));
            var c = UIGraphics.GetCurrentContext ();

            theImage.Draw (new RectangleF (0, 0, width, height));
            var converted = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            return converted;
        }
开发者ID:Clancey,项目名称:Facetroids,代码行数:19,代码来源:Graphics.cs

示例13: RenderImageWithShadow

			UIImage RenderImageWithShadow (UIImage image, float radius, UIColor color)
			{
				var size = new SizeF (image.Size.Width+8, image.Size.Height+8);
				
				BeginImageContext (size);
				var ctx = UIGraphics.GetCurrentContext ();

				ctx.SaveState ();
				ctx.SetShadowWithColor (new SizeF (1, 1), radius, color.CGColor);
				image.Draw (new PointF (4, 4));
				ctx.RestoreState ();

				image.Draw (new PointF (4, 4));
				
				image = UIGraphics.GetImageFromCurrentImageContext ();

				UIGraphics.EndImageContext ();
				
				return image;
			}
开发者ID:21Off,项目名称:21Off,代码行数:20,代码来源:SweepSupport.cs

示例14: AddImageReflection

        public static UIImage AddImageReflection(UIImage image, float reflectionFraction)
        {
            int reflectionHeight = (int) (image.Size.Height * reflectionFraction);

            // Create a 2 bit CGImage containing a gradient that will be used for masking the
            // main view content to create the 'fade' of the reflection.  The CGImageCreateWithMask
            // function will stretch the bitmap image as required, so we can create a 1 pixel wide gradient

            // gradient is always black and white and the mask must be in the gray colorspace
            var colorSpace = CGColorSpace.CreateDeviceGray ();

            // Creat the bitmap context
            var gradientBitmapContext = new CGBitmapContext (IntPtr.Zero, 1, reflectionHeight, 8, 0, colorSpace, CGImageAlphaInfo.None);

            // define the start and end grayscale values (with the alpha, even though
            // our bitmap context doesn't support alpha the gradien requires it)
            float [] colors = { 0, 1, 1, 1 };

            // Create the CGGradient and then release the gray color space
            var grayScaleGradient = new CGGradient (colorSpace, colors, null);
            colorSpace.Dispose ();

            // create the start and end points for the gradient vector (straight down)
            var gradientStartPoint = new PointF (0, reflectionHeight);
            var gradientEndPoint = PointF.Empty;

            // draw the gradient into the gray bitmap context
            gradientBitmapContext.DrawLinearGradient (grayScaleGradient, gradientStartPoint,
                                                      gradientEndPoint, CGGradientDrawingOptions.DrawsAfterEndLocation);
            grayScaleGradient.Dispose ();

            // Add a black fill with 50% opactiy
            gradientBitmapContext.SetGrayFillColor (0, 0.5f);
            gradientBitmapContext.FillRect (new RectangleF (0, 0, 1, reflectionHeight));

            // conver the context into a CGImage and release the context
            var gradientImageMask = gradientBitmapContext.ToImage ();
            gradientBitmapContext.Dispose ();

            // create an image by masking the bitmap of the mainView content with the gradient view
            // then release the pre-masked content bitmap and the gradient bitmap
            var reflectionImage = image.CGImage.WithMask (gradientImageMask);
            gradientImageMask.Dispose ();

            var size = new SizeF (image.Size.Width, image.Size.Height + reflectionHeight);

            // Use BeginImageContextWithOptions for retina images (only available on is 4.0 and up).
            // http://stackoverflow.com/questions/6965873/drawing-on-the-retina-display-using-coregraphics-image-pixelated
            if (UIScreen.MainScreen.RespondsToSelector(new Selector("scale")))
            {
                UIGraphics.BeginImageContextWithOptions(size, false, UIScreen.MainScreen.Scale);
            }
            else
            {
                UIGraphics.BeginImageContext (size);
            }

            image.Draw (PointF.Empty);
            var context = UIGraphics.GetCurrentContext ();
            context.DrawImage (new RectangleF (0, image.Size.Height, image.Size.Width, reflectionHeight), reflectionImage);

            var result = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            reflectionImage.Dispose ();

            return result;
        }
开发者ID:migueldeicaza,项目名称:OpenFlowSharp,代码行数:67,代码来源:ImageUtils.cs

示例15: CropImage

 private UIImage CropImage(UIImage sourceImage, int crop_x, int crop_y, int width, int height)
 {
     var imgSize = sourceImage.Size;
     UIGraphics.BeginImageContext(new SizeF(width, height));
     var context = UIGraphics.GetCurrentContext();
     var clippedRect = new RectangleF(0, 0, width, height);
     context.ClipToRect(clippedRect);
     var drawRect = new RectangleF(-crop_x, -crop_y, imgSize.Width, imgSize.Height);
     sourceImage.Draw(drawRect);
     var modifiedImage = UIGraphics.GetImageFromCurrentImageContext();
     UIGraphics.EndImageContext();
     return modifiedImage;
 }
开发者ID:WenF,项目名称:FlagThis,代码行数:13,代码来源:FT_MessageViewController.cs


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