是否有人能夠幫助我將這種方法在ios中轉換爲mac版本?代碼是用C#在Xamarin翻譯CGContext生成圖像方法從ios到mac
public static UIImage GetImageFromColor(UIColor color, float borderWidth = 1.0f)
{
var rect = new CGRect(0.0f, 0.0f, borderWidth, borderWidth);
UIGraphics.BeginImageContext(rect.Size);
var context = UIGraphics.GetCurrentContext();
context.SetFillColor(color.CGColor);
context.FillRect(rect);
var image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return image.CreateResizableImage(new UIEdgeInsets(1.0f, 1.0f, 1.0f, 1.0f));
}
的感謝!我想知道如果我想使用一個CGContext,而應該如何從那裏做一個NSImage或CGImage?看起來,Apple有一個內置的makeImage()方法,而xamarin沒有 – Xiangyu
@Xiangyu Swift的'makeImage'是一個ObjC'CGBitmapContextCreateImage',只能通過位圖上下文獲得,而Xamarin的'ToImage'則是'CGBitmapContextCreateImage' – SushiHangover