我找到了这个,但还没试过自己:
http://reusablesnippets.posterous.com/capture-uiview
在这里您可以找到使用的 -renderInContext http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004500-CH1-SW120
编辑
我将上面的代码转换为UIView上的一个类别.这样叫:[aView saveScreenshotToPhotosAlbum];
#import <QuartzCore/QuartzCore.h>
- (UIImage*)captureView {
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
- (void)saveScreenshotToPhotosAlbum {
UIImageWriteToSavedPhotosAlbum([self captureView], nil, nil, nil);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2223 次 |
| 最近记录: |