从MPMoviePlayerController调整缩略图的大小

时间:2014-02-26 04:35:02

标签: ios objective-c resize mpmovieplayercontroller

我试图使用MPMoviePlayerController从使用UIImagePickerController捕获的视频中调整缩略图。这是我正在使用的:

         self.moviePlayer.contentURL = [info objectForKey:UIImagePickerControllerMediaURL];
        UIImage *thumbnail = [self.moviePlayer thumbnailImageAtTime:1 timeOption:MPMovieTimeOptionNearestKeyFrame];
        self.thumbnailImage = [self resizeImage:thumbnail toWidth:75.0 andHeight:75.0];

这是我的调整大小方法:

- (UIImage *)resizeImage:(UIImage *)image toWidth:(float)width andHeight:(float)height {

    CGSize newSize = CGSizeMake(width, height);

    CGRect newRect = CGRectMake(0, 0, width, height);

    UIGraphicsBeginImageContext(newSize);
    [self.image drawInRect:newRect];
    UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return resizedImage;

}

调整大小方法适用于在imagePicker中捕获的照片,但由于某些原因,当我在视频缩略图上使用它时,图像为空白。如果我不调整大小它看起来很好,但由于某种原因调整大小会搞砸它。即时通讯使用ios7并在iPhone 5s上进行测试

1 个答案:

答案 0 :(得分:1)

UIGraphicsBeginImageContext(newSize);
[image drawInRect:newRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

我使用[self.image drawInRect]而不是[image drawInRect]愚蠢的错误。哇。

相关问题