Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 03-21-2009, 07:00 PM   #1 (permalink)
bhearn
New Member
 
Join Date: Aug 2008
Posts: 125
Default background threads and graphics

I need to resize an image smaller in a background thread.

This trick:

Code:
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
often crashes, I think because the change to the graphics context stack can interfere with any drawing on the main thread.

There's also the undocumented API _imageScaledToSize, for which you don't need to (explicitly, anyway) change the graphics context, but this seems to crash occasionally as well.

Any other ways anyone can think of? Unfortunately doing it in the main thread is really not an option. When we get a photo from the photo picker, and it was taken with the camera, it takes a couple of seconds to resize, and we can't freeze the interface for that long.

The docs are not very clear on what kind of drawing is allowable in background threads. There is this:

Quote:
The Application Kit is generally thread-safe when drawing with its graphics functions and classes, including the NSBezierPath and NSString classes. Details for using particular classes are described in the following sections. Additional information about drawing and threads is available in Cocoa Drawing Guide.
But though this is in the iPhone docs, it seems to apply only to Mac OS X.
bhearn is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,844
Threads: 89,212
Posts: 380,654
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jonesstr
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:28 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.