Skip to Main Content
Basic Sensors in iOS
book

Basic Sensors in iOS

by Alasdair Allan
July 2011
Beginner to intermediate content levelBeginner to intermediate
108 pages
2h 29m
English
O'Reilly Media, Inc.
Content preview from Basic Sensors in iOS

Video Thumbnails

There is no easy way to retrieve a thumbnail of a video, unlike still photos. This section illustrates two methods of grabbing raw image data from an image picker.

Video Thumbnails Using the UIImagePicker

One way to grab a video frame for creating a thumbnail is to drop down to the underlying Quartz framework to capture an image of the picker itself. To do so, add the following highlighted code to the image picker delegate described previously in this chapter:

-(void)imagePickerController:(UIImagePickerController *)picker 
      didFinishPickingMediaWithInfo:(NSDictionary *)info {
      
    if( [info objectForKey:@"UIImagePickerControllerMediaType"] ==
        kUTTypeMovie ) {
        CGSize pickerSize = CGSizeMake(picker.view.bounds.size.width,
                                       picker.view.bounds.size.height-100);
        UIGraphicsBeginImageContext(pickerSize);
        [picker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *thumbnail = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        imageView.image = thumbnail;

    } else {
          imageView.image = image;

    }
    [self dismissModalViewControllerAnimated:YES];
}

Since picker.view.layer is part of the UIView parent class and is of type CALayer, the compiler doesn’t know about renderInContext: method unless you import the QuartzCore header file. Add the following to the implementation file:

#import <QuartzCore/QuartzCore.h>

Video Thumbnails Using AVFoundation

Another method to obtain a thumbnail that will result in a better image is to use the AVFoundation framework. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Building iPhone and iPad Electronic Projects

Building iPhone and iPad Electronic Projects

Mike Westerfield
iPhone and iPad App 24-Hour Trainer

iPhone and iPad App 24-Hour Trainer

Abhishek Mishra, Gene Backlin
BioCoder #3

BioCoder #3

O'Reilly Media, Inc.
iOS 7 Programming Cookbook

iOS 7 Programming Cookbook

Vandad Nahavandipoor

Publisher Resources

ISBN: 9781449309480Supplemental ContentErrata Page