Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Stone Preston
42,016 Pointsproblem resizing image from MPMoviePlayer Thumbnail
im trying to resize a thumbnail obtained from an MPMoviePlayer (im displaying image and video thumbnails in a collection view and saving the thumbnails to parse) but whenever I resize the thumbnail my new resized image is blank and white. If I dont resize it, its fine (its just not the right size). Here is my code
//create the thumbnail for the video
self.moviePlayer.contentURL = [info objectForKey:UIImagePickerControllerMediaURL];
UIImage *thumbnail = [self.moviePlayer thumbnailImageAtTime:1 timeOption:MPMovieTimeOptionNearestKeyFrame];
NSLog(@" original thumbnail:%@ width:%f height:%f", thumbnail, thumbnail.size.width
, thumbnail.size.height);
self.thumbnailImage = [self resizeImage:thumbnail toWidth:75.0 andHeight:75.0];
NSLog(@"resized thumbnail:%@ width:%f height:%f", self.thumbnailImage, self.thumbnailImage.size.width
, self.thumbnailImage.size.height);
self.thumbnail is the resized thumbnail, and the logs for the width and height show 75 x 75 as its size, however its just a blank white image when I view it in the parse data browser. If I upload the unresized image to parse I can view it fine in the data browser so it looks like something is wrong with my resizing. Here is the method I use to resize:
- (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;
}
im testing on ios7 with an iPhone 5s maybe Amit Bijlani or Ben Jakuben can help me out?
2 Answers
Holger Liesegang
50,595 PointsHi Stone,
your "resizeImage" method looks just fine but you might want to use
[image drawInRect:newRect];
instead of
[self.image drawInRect:newRect];
as you have an "(UIImage *)image" form the method signature but maybe I'm totally wrong here and you want to use your image property "image" on purpose.
Kind Regards Holger
Holger Liesegang
50,595 PointsThank you, Ben Jakuben - I'm going to work on that part - at least that's what I keep telling myself for some weeks :-)
Stone Preston
42,016 PointsStone Preston
42,016 Pointsawesome! thanks for catching that. i wont be able to test it until later today to see if it works but im almost positive thats it. good eye
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherHolger Liesegang, you have an amazing point total! Looks like you need more Android points, though.
Stone Preston
42,016 PointsStone Preston
42,016 Pointsthat was the problem. thanks a ton