.net - Objective-C to Monotouch (.NET) 单行代码转换

标签 .net objective-c ios xamarin.ios

我有这 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/

相关文章:

ios - 如何使用新的 pencilkit api 注释 pdf?

ios - 在设备旋转时更新 tableView 标题 View

c# - 错误 : Must create DependencySource on same Thread as the DependencyObject even by using Dispatcher

c# - 在 Entity Framework 中使用 DbContext 运行异步调用

ios - 使用 iOS 10.2 版在同一设备上获取不同的 UUID

iphone - Xcode 中的重复声音问题

ios - 在 UIWebView 中仅加载网站上的 div

c# - TFS 2010 API - 遍历 QueryHistory 中返回的变更集列表太慢了

c# - .RemoveRange 在 Entity Framework 中不首先获取数据库记录

ios - Swift 在 UITableViewCell 内的 UICollectionView 中以单选/多选模式选择/取消选择