我有这 3 行。中间那个,不知道怎么转换:
源 Obj-C
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
Objective-C#
CGContext ctx = UIGraphics.GetCurrentContext ();
// ??? [[UIColor blackColor] set]; ???
ctx.FillRect (screenRect);
最佳答案
这是我为任何需要 MonoTouch 版本的人制作的完整屏幕截图代码:
public static UIImage TakeScreenShot (UIView view)
{
try
{
RectangleF canvasRect = view.Bounds;
UIGraphics.BeginImageContext (canvasRect.Size);
CGContext ctx = UIGraphics.GetCurrentContext ();
ctx.FillRect (canvasRect);
view.Layer.RenderInContext (ctx);
UIImage newImage = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
return newImage;
}
catch
{
return null;
}
}
关于.net - Objective-C to Monotouch (.NET) 单行代码转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6313574/