IOS如何创建视频缩略图片
2015-12-23 18:57
471 查看
[align=center]IOS如何创建视频缩略图片[/align]
![](http://www.cnblogs.com/ac/b.gif)
原来图片太大,对原来图片进行压缩,这个函数就是压缩图片,生成一个小头像
//将完整的图片和缩略后的图片写入临时文件夹中
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
![](http://www.cnblogs.com/ac/b.gif)
原来图片太大,对原来图片进行压缩,这个函数就是压缩图片,生成一个小头像
//将完整的图片和缩略后的图片写入临时文件夹中
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中plist的创建,数据写入与读取
- ios条形码扫描技术
- ios开发 向右滑动手势实现返回 -- @ShinePug
- 30多个iOS常用动画,带详细注释(转)
- iOS
- IOS类别通过关联对象添加属性
- IOS图片加载方式:imageNamed和imageWithContentsOfFile的区别
- iOS9应用适配,技Get
- ios开发之svn频繁使用的命令
- ios手势操作:单双击(点按)、长按、捏合、拖拽、旋转、横扫
- iOS静态库的制作
- xCode6新建工程部署到iOS7设备上不能全屏显示
- iOS 枚举类型学习
- 苹果企业开发者应用plist文件的配置
- iOS开发中使用CIDetector检测人脸
- iOS摄像头和相册
- 在IOS开发中使用自定义的字体
- iOS通知如何传值?
- iOS中Block介绍(二)内存管理与其他特性
- iOS透明viewControler