Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
- Subject: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
- From: Ray <email@hidden>
- Date: Tue, 27 Mar 2012 12:42:58 +0200
Thanks Giacomo for your answer, but the problem is not so much that the resizing doesn't work, but that [UIImage imageWithData:listImage] always returns a scale of 1.0 for the image. This means that I encounter the problem described, when images are saved using an iPhone with a retina screen... (deployment target is iOS 4).
On Mar 27, 2012, at 11:57 AM, Giacomo Tufano wrote:
> Il giorno 27/mar/2012, alle ore 09:38, Ray ha scritto:
>
>> OK, so I have this iOS 3.x code base that I need to update. I have the following code, to make a thumbnail image:
>> Code is simplified, just for illustrative purposes. I store imageData as a binary property (called "listImage") in a Core Data entity and use it as a thumbnail image in a UITableView, like so:
>>
>> But this seems kludgy and it's using programmer's knowledge, so to speak. I watched WWDC2010 session 134 "Optimize your iPhone App for the Retina Display" again, searched stackoverflow etc. but I can't find a more elegant solution. What would be a more thorough approach? Maybe it's staring me in the face but I don't see it...
>
> That's what I use to generate a thumbnail of sideSize side lenght in iOS3.x code.
> It uses iOS4+ functions for retina displays (I remember that you can assume iOS4+ with retina displays).
>
> CGSize newSize = CGSizeMake(sideSize, sideSize);
> #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
> if(UIGraphicsBeginImageContextWithOptions != NULL)
> UIGraphicsBeginImageContextWithOptions(newSize, NO, [[UIScreen mainScreen] scale]);
> else
> #endif
> UIGraphicsBeginImageContext(newSize);
> UIGraphicsBeginImageContext(newSize);
> [self drawInRect:CGRectMake(0, 0, sideSize, sideSize)];
> // Get the new image from the context
> UIImage *thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
> // End the context
> UIGraphicsEndImageContext();
>
> It works correctly on retina displays.
> To be honest I don't remember why I use that macro to test for iOS4, there were a reason and that was a workaround but cannot remember why. It works, anyway. :)
>
> HTH,
> gt
>
> ---
> Giacomo Tufano
> Stat rosa pristina nomine, nomina nuda tenemus.
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden