【问题标题】:Capture the Non-Active UIView as an UIImage将非活动 UIView 捕获为 UIImage
【发布时间】:2012-06-16 08:16:25
【问题描述】:

下面的代码运行良好,但只抓取屏幕上可见的 UIView。 如何获取当前未显示的 UIView?

谢谢!

    //Take a screenshot of the view...
UIGraphicsBeginImageContext(View_1.frame.size);
    [View_1.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *View_1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(View_1, nil, nil, nil);

//...and attach it as an image to the email
NSData *myData3 = UIImagePNGRepresentation(View_1);
[picker addAttachmentData:myData3 mimeType:@"image/png" fileName:@"screenshot2"];   

【问题讨论】:

    标签: iphone ios5 ios4


    【解决方案1】:

    如果您的意思是像view.hidden = YES; 那样隐藏,那么您将无法绘制它,而不是隐藏它,您可以将其从超级视图中删除,或者甚至在绘制之前调用view.hidden = NO;,然后调用view.hidden = YES;画完之后

    例子

    //Take a screenshot of the view...
    UIGraphicsBeginImageContext(View_1.frame.size);
    //Set it to visible
    View_1.hidden = NO;
    [View_1.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *View_1 = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(View_1, nil, nil, nil);
    //Hide it again
    View_1.hidden = YES;
    //...and attach it as an image to the email
    NSData *myData3 = UIImagePNGRepresentation(View_1);
    [picker addAttachmentData:myData3 mimeType:@"image/png" fileName:@"screenshot2"];
    

    【讨论】:

    • 你是个天才!它确实被设置为隐藏...非常感谢您的帮助。 :-)
    • 虽然与问题的标题不太相关...您知道是否可以在附件中添加超过 1 张图片吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 1970-01-01
    相关资源
    最近更新 更多