【发布时间】:2017-06-23 07:11:04
【问题描述】:
我正在尝试在我的 Mac 应用程序中调整图像的大小,就像我之前在 iOS 应用程序中所做的那样。问题是 NSImage 不包含 UIImage 所做的所有方法。这是我用于 iOS 的代码
public static UIImage MaxResizeImage(this UIImage sourceImage, float maxWidth, float maxHeight)
{
var sourceSize = sourceImage.Size;
var maxResizeFactor = Math.Max(maxWidth / sourceSize.Width, maxHeight / sourceSize.Height);
if (maxResizeFactor > 1) return sourceImage;
float width = (float)(maxResizeFactor * sourceSize.Width);
float height = (float)(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;
}
如何为 Mac-App 重写它?感谢您的帮助
【问题讨论】:
-
如果没有解决请接受anwser或添加评论
标签: ios xamarin xamarin.ios nsimage xamarin.mac