Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
- Subject: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
- From: David Duncan <email@hidden>
- Date: Tue, 27 Mar 2012 10:29:26 -0700
On Mar 27, 2012, at 12:38 AM, Ray wrote:
> Now, when I generate a new image on an iPhone with a retina screen, in which case the above UIGraphicsBeginImageContextWithOptions uses a scale of 2.0, the image in the table view shows too big. This is because [UIImage imageWithData:item.listImage] always returns a 1.0 scaled image. Now I can solve this by using something like:
>
> UIImage *theImage = [UIImage imageWithData:listImage];
> [UIImage imageWithCGImage:theImage.CGImage scale:theImage.size.width > 44.0 ? 2.0 : 1.0 orientation:theImage.imageOrientation];
>
> 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...
Simplest solution is to save the scale along side the image itself (under the assumption that this data can possibly end up on a non-retina device for some reason) or to create a new UIImage with the screen scale via +imageWIthCGImage:scale:orientation: (assuming it cannot) after you load it with +imageWithData:.
--
David Duncan
_______________________________________________
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