標籤:
IOS如何建立影片縮圖片
//將完整的圖片和縮減後的圖片寫入臨時檔案夾中
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
IOS如何建立影片縮圖片