Objective-C到Monotouch(.NET)单行代码转换
我有这三行。中间那个,我不知道怎么转换: 源Obj-CObjective-C到Monotouch(.NET)单行代码转换,.net,objective-c,ios,xamarin.ios,.net,Objective C,Ios,Xamarin.ios,我有这三行。中间那个,我不知道怎么转换: 源Obj-C CGContextRef ctx = UIGraphicsGetCurrentContext(); [[UIColor blackColor] set]; CGContextFillRect(ctx, screenRect); 目的地C# 通过谷歌搜索,它看起来像是: UIColor.Black.SetColor(); 如果这不起作用,那么-set相当于-setFill和-setStroke,因此这可能会起作用: UIColor.
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
目的地C#
通过谷歌搜索,它看起来像是:
UIColor.Black.SetColor();
如果这不起作用,那么-set
相当于-setFill
和-setStroke
,因此这可能会起作用:
UIColor.Black.SetFill();
UIColor.Black.SetStroke();
另请参见:从一些谷歌搜索中,它看起来像是:
UIColor.Black.SetColor();
如果这不起作用,那么-set
相当于-setFill
和-setStroke
,因此这可能会起作用:
UIColor.Black.SetFill();
UIColor.Black.SetStroke();
另请参见:以下是我为需要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;
}
}
以下是我为需要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;
}
}
我相信你想要模仿另一种行为的路线是
UIColor.Black.SetColor ();
…或者,也许是交替地
ctx.SetFillColor(UIColor.Blue.CGColor);
我相信你想要模仿另一种行为的路线是
UIColor.Black.SetColor ();
…或者,也许是交替地
ctx.SetFillColor(UIColor.Blue.CGColor);
如果您正在转换上一个问题的屏幕截图,这甚至可能没有必要,因为我相信这是默认设置。如果你正在转换上一个问题的截图,这甚至可能不是必需的,因为我相信这是默认设置。请在不使用的情况下尝试,然后查看。感谢您共享您的代码。我正在使用它从视图创建图像。问题是,当创建图像时,背景仍然是黑色的。你知道如何设置alpha吗?谢谢你分享你的代码。我正在使用它从视图创建图像。问题是,当创建图像时,背景仍然是黑色的。你知道如何设置alpha吗?