//将完整的图片和缩略后的图片写入临时文件夹中
NSData *pngImage = UIImagePNGRepresentation(thumbnail);
if ([pngImage writeToFile:[NSString stringWithFormat:@"%@/tempImage.png",TEMP_FOLDER] atomically:YES]) {
UIImage *myThumbNail = [[UIImage alloc] initWithData:pngImage];
UIGraphicsBeginImageContext(CGSizeMake(60.0, 60.0));
[myThumbNail drawInRect:CGRectMake(0.0, 0.0, 60.0, 60.0)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *thumbView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 60.0, 60.0)];
thumbView.image = newImage;
[self.view addSubview:thumbView];
NSData *thumbData = UIImagePNGRepresentation(newImage);
if ([thumbData writeToFile:[NSString stringWithFormat:@"%@/tempImageThumb.png"] atomically:YES]) {
NSLog(@"thumb written!");
}
}
视频图片可以从视频中截取
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:movieUrl];
UIImage *thumbnail = [_moviePlayerthumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame