从视频创建缩略图 - 通过MPMoviePlayerController提高速度性能

时间:2013-07-23 06:52:15

标签: ios objective-c mpmovieplayercontroller

这是我正在使用的代码。我希望生成缩略图之后我通过这些缩略图创建一个视频,并在“drawImage”UIImageView上完成绘图。

   while([self.thunbnailArray count])
    {
        id times = [self.thunbnailArray objectAtIndex:0];////self.thumbnailArray contains duratin of player at which thumbnail generate//////
        [self.thunbnailArray removeObjectAtIndex:0];
        UIImage* thumbnail = [player1 thumbnailImageAtTime:[times floatValue]             timeOption:MPMovieTimeOptionExact];

        UIGraphicsBeginImageContext(drawImage.frame.size);////drawImage is a UIImageView to make drawing
        [drawImage.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        CGImageRef firstImageRef = thumbnail.CGImage;/////merge thumbnail and drawing both together
        CGFloat firstWidth = CGImageGetWidth(firstImageRef);
        CGFloat firstHeight = CGImageGetHeight(firstImageRef);
        CGSize mergedSize = CGSizeMake(firstWidth, firstHeight);
        UIGraphicsBeginImageContext(mergedSize);
        [thumbnail drawInRect:CGRectMake(0, 0, firstWidth, firstHeight)];
        [viewImage drawInRect:CGRectMake(0, 0, firstWidth, firstHeight)];
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        [self.imageArray addObject:newImage];///self.imageArray used to generate video

    }

0 个答案:

没有答案