youknowone / FoundationExtension

Foundation/Cocoa/UIKit extension kit. Reference document:

Home Page:http://youknowone.github.io/FoundationExtension

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UIImageAdditions imageByResizingToSize returns a blank image

nebiros opened this issue · comments

UIImageAdditions imageByResizingToSize returns a blank image, here's my code:

#import <FoundationExtension/UIImageAdditions.h>

...

UIImage *compassImage = [UIImage imageNamed:@"compass.png"];
UIImage *compassImageThumb = [compassImage imageByResizingToSize:CGSizeMake(20.0, 20.0)];
UIBarButtonItem *compassButtonItem = [[UIBarButtonItem alloc] initWithImage:compassImageThumb style:UIBarButtonItemStyleBordered target:self action:@selector(compassButtonPressed:)];
self.navigationItem.rightBarButtonItem = compassButtonItem;

This is what I got:

UIImage

The compass.png image:

UIImage

BTW, using UIGraphicsBeginImageContext to resize the image using a CGSize works!, the code:

UIImage *compassImage = [UIImage imageNamed:@"compass.png"];
CGSize newSize = CGSizeMake(20.0, 20.0);
UIGraphicsBeginImageContext(newSize);
[compassImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *compassImageThumb = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Thanks! Was it on simulator? I got a report that this works only on device before.

And thank you for the patch code!

@youknowone Yes!, on the simulator. No problem, great lib, :).

I replaced the code from yours, thanks ;)