0

我需要将 UITableViewCell 导出为 PNG 或任何图像,以便我可以使用 MFMailComposerViewController 将其作为嵌入在电子邮件正文中的打印屏幕图像发送。

4

3 回答 3

2

使用这些方法。打电话UIImage *image = [cell screenshot];

- (UIImage *)screenshot
{
    return [self screenshotForRect:self.bounds];
}

- (UIImage *)screenshotForRect:(CGRect) rect
{
    UIGraphicsBeginImageContext(rect.size);
    [[UIColor clearColor] setFill];
    [[UIBezierPath bezierPathWithRect:rect] fill];
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [self.layer renderInContext:ctx];
    UIImage *anImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();    
    return anImage;
}
于 2012-12-03T10:59:55.033 回答
1

尝试这样的事情:

UIGraphicsBeginImageContext(yourTableViewCellView.bounds.size);
[yourTableViewCellView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

然后您可以将图像保存到数据:)

于 2012-12-03T10:59:30.863 回答
1
- (UIImage *)captureCell {

    //hide controls if needed
CGRect rect = [yourTableCell bounds];

    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [yourTableCell.layer renderInContext:context];   
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;

}
于 2012-12-03T10:59:41.053 回答