Challenge: Shrinking the Main Image


#1

Hi,

In order to solve this challenge, is enough to invoke the method “imageWithCGImage:scale:orientation:” before storing the image in the NSDictionary? Such as:

- (void)setImage:(UIImage *)i forKey:(NSString *)s
{
    UIImage *scaledImage = [UIImage imageWithCGImage:i.CGImage 
                                               scale:0.25
                                         orientation:i.imageOrientation];    
    [dictionary setObject:scaledImage forKey:s];    
    ...

Thanks in advance,

Gabriel.


#2

i’m not sure. but when i tried it it didn’t fix the stutter.

so — i’m thinking no?


#3

This worked for me… placed in ItemDetailViewController -> imagePickerController:didFinishPickingMediaWithInfo:

// Shrink it down to make things faster for the UI CGSize imgSize = [img size]; float scale = 0.3; CGSize smallSize = CGSizeMake(imgSize.width * scale, imgSize.height * scale); UIGraphicsBeginImageContext(smallSize); [img drawInRect:CGRectMake(0, 0, smallSize.width, smallSize.height)]; img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();


#4

Thank you. For those who wonders where to put, refer to the following

// Get picked image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

//make it smaller

CGSize imgSize = [image size];
float scale = 0.3;
CGSize smallSize = CGSizeMake(imgSize.width * scale, imgSize.height * scale);
UIGraphicsBeginImageContext(smallSize);
[image drawInRect:CGRectMake(0, 0, smallSize.width, smallSize.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Create a CFUUID object - it knows how to create unique identifier strings
CFUUIDRef newUniqueID = CFUUIDCreate(kCFAllocatorDefault);