• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions


  • Subject: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • From: Giacomo Tufano <email@hidden>
  • Date: Tue, 27 Mar 2012 11:57:24 +0200

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

  • Follow-Ups:
    • Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
      • From: David Duncan <email@hidden>
    • Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
      • From: Ray <email@hidden>
References: 
 >Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions (From: Ray <email@hidden>)

  • Prev by Date: Re: How to throttle rate of NSInputStream?
  • Next by Date: Re: How to throttle rate of NSInputStream?
  • Previous by thread: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • Next by thread: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • Index(es):
    • Date
    • Thread