2 bluetooth99 bluetooth99 于 2012.12.04 10:26 提问

将UITableViewCell导入PNG

要求用到UITableViewCell导入到一个图片,PNG或者其他格式,实现使用MFMailComposerViewController通过Email传递。请高手帮忙。

3个回答

lanhailvcao
lanhailvcao   2012.12.04 11:15
已采纳

调用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;
}
bluetooth99
bluetooth99 谢谢
大约 5 年之前 回复
xinyoulingxi1_tong
xinyoulingxi1_tong   2012.12.04 11:31
UIGraphicsBeginImageContext(yourTableViewCellView.bounds.size);
[yourTableViewCellView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

可以存储图片

MrsSeven7
MrsSeven7   2012.12.04 13:43
- (UIImage *)captureCell {

CGRect rect = [yourTableCell bounds];

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

}
bluetooth99
bluetooth99 谢谢你, 也帮了忙
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!