本文整理汇总了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);
}
示例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;
}
}
}