截屏

本文转载至 : http://gaohaijun.blog.163.com/blog/static/17669827120113193939499/

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0f);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imgData = UIImagePNGRepresentation(img);

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"t.png"];
[imgData writeToFile:filePath atomically:YES];

 

 

1.第一种

 

    UIGraphicsBeginImageContextWithOptions(self.view.bounds.sizeYES1.0f);

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *uiImage = UIGraphicsGetImageFromCurrentImageContext();

 

2.第二种是私有方法,可能会不通过,也有人尝试提交成功的

    CGImageRef img = UIGetScreenImage();

    UIImage* uiImage=[UIImage imageWithCGImage:img];

 

3.获取视频截图

 

UIImage *uiImage = [moviePlayer thumbnailImageAtTime:moviePlayer.currentPlaybackTime

                                                timeOption:MPMovieTimeOptionNearestKeyFrame];

 

posted @ 2013-06-05 13:40  天牛  阅读(145)  评论(0)    收藏  举报