當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。