Convert UIWebview contents to a UIImage when the webview is larger than the screen

后端 未结 5 1163
孤城傲影
孤城傲影 2020-12-02 19:20

Very similar to this question (and also this answer), I\'m trying to make an UIImage out from a webview. So far I\'m using the code suggested in the answer, specifically: <

5条回答
  •  暖寄归人
    2020-12-02 20:11

    If someone is struggling how to do this in Xamarin, based on @DR answer, here is the code:

    var image = new UIImage();
    
    var previousFrame = _tableView.Frame;
    var newFrame = new CGRect(new CGPoint(0, 0), _tableView.ContentSize);
    View.Frame = newFrame;
    
    UIGraphics.BeginImageContextWithOptions(_tableView.ContentSize, false, UIScreen.MainScreen.Scale);
    var context = UIGraphics.GetCurrentContext();
    View.Layer.RenderInContext(context);
    image = UIGraphics.GetImageFromCurrentImageContext();
    
    UIGraphics.EndImageContext();
    
    View.Frame = previousFrame;
    
    
    return image;
    

提交回复
热议问题