现在的位置: 首页 > 综合 > 正文

将iPhone的当前画面UIView保存为图片

2014年09月05日 ⁄ 综合 ⁄ 共 453字 ⁄ 字号 评论关闭

将iPhone的当前画面UIView保存为图片

2009年07月28日 星期二 13:26

你是不是也想过将当前的UIView作为图片保存到iPhone的Photo Albums呢。

下面给出实现该功能的代码。非常简单,5行就搞定了。

    UIGraphicsBeginImageContext(currentView.bounds.size);

    [currentView.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

最后别忘了添加QuartzCore.framework和导入头文件#import <QuartzCore/QuartzCore.h>

抱歉!评论已关闭.