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


C# UIImage.Dispose方法代码示例

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


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

示例1: DidCropToImage

		public override void DidCropToImage (TOCropViewController cropViewController, UIImage image, CoreGraphics.CGRect cropRect, nint angle)
		{
			DidCrop = true;

			try 
			{
				if (image != null)
					App.CroppedImage = image.AsPNG().ToArray();

			}
			catch (Exception ex) {
				Debug.WriteLine (ex.Message);
			}
			finally
			{
				if (image != null) {
					image.Dispose ();
					image = null;
				}
			}

			parent.DismissViewController (true, App.PopModal);
		}
开发者ID:BradleyDHobbs,项目名称:Xamarin.CropView,代码行数:23,代码来源:CropViewDelegate.cs

示例2: Resize

		/// <summary>
		/// Resize the image in byte array originalImageData to reqWidth and reqHeight.
		/// </summary>
		/// <remarks>If one of width or height is 0, the image is resized preserving the ratio.</remarks>
		/// <param name="originalImageData">Original image as byte array.</param>
		/// <param name="reqWidth">Req width.</param>
		/// <param name="reqHeight">Req height.</param>
		public byte[] Resize(byte[] originalImageData, int reqWidth, int reqHeight)
		{
			// Found at http://forums.xamarin.com/discussion/5697/resize-an-image-while-retaining-quality
			// and at http://bortolu.wordpress.com/2014/03/21/xamarin-c-how-to-convert-byte-array-to-uiimage-with-an-extension-method/

			if (originalImageData == null) 
			{
				return null;
			}

			UIImage image = null;

			try
			{
				image = new UIImage(NSData.FromArray(originalImageData));
			}
			catch (Exception)
			{
				return null;
			}

			UIGraphics.BeginImageContext(new CGSize(reqWidth, reqHeight));

			CGContext context = UIGraphics.GetCurrentContext();
			context.InterpolationQuality = CGInterpolationQuality.None;

			context.TranslateCTM(0, reqHeight);
			context.ScaleCTM(1f, -1f);

			context.DrawImage(new CGRect(0, 0, reqWidth, reqHeight), image.CGImage);

			image.Dispose();
			image = null;

			using (var scaledImage = UIGraphics.GetImageFromCurrentImageContext())
			{
				UIGraphics.EndImageContext();

				if (scaledImage == null)
				{
					return null;
				}

				NSData data = null;

				try
				{
					data = scaledImage.AsPNG();
					return data.ToArray();
				}
				catch (Exception)
				{
					return null;
				}
				finally
				{
					data.Dispose();
					data = null;
				}
			}
		}
开发者ID:Surfoo,项目名称:WF.Player,代码行数:68,代码来源:ImageTools.cs


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