On Mar 29, 2008, at 12:20 PM, Trygve Inda wrote:

How about:

NSImage *    image = [[[NSImage alloc] initWithContentsOfFile:path]
autorelease];

[...]

Drawing into an NSImage is explicitly documented to be thread safe in
the article you linked to,

I guess I was more concerned with the initWithContentsOfFile:path

For my own code, I'd tend to assume it's safe since it should just be a wrapper around ImageIO. However, sometimes Cocoa adds an unexpected layer of thread-unsafety (e.g. NSRunLoop vs. CFRunLoop), and the Cocoa API docs aren't as helpful as the Carbon ones for thread safety.

and each thread has its own graphics
context.  The post I linked to does indicate that you might want to
use [image setCacheMode:NSImageCacheNever].  If your goal is just to
get an NSBitmapImageRep from a file, it's probably easier just to use
+imageRepWithContentsOfFile:.

This could work, but as I need to do pixel level manipulation, I really need to know the exact format of the bitmap and this does not seem to let me
specify it.

That makes sense. You could also introspect the returned imagerep and see if it matches your desired format, then only redraw it if necessary. For messing with pixels, I'd avoid NSImage altogether and just use ImageIO to create a CGImage, then draw that into your NSBitmapImageRep with [[NSGraphicsContext graphicsContextWithBitmapImageRep:] graphicsPort] as the CGContext.

--
adam
On Mar 29, 2008, at 12:20 PM, Trygve Inda wrote:

How about:

NSImage *    image = [[[NSImage alloc] initWithContentsOfFile:path]
autorelease];

[...]

Drawing into an NSImage is explicitly documented to be thread safe in
the article you linked to,

I guess I was more concerned with the initWithContentsOfFile:path

For my own code, I'd tend to assume it's safe since it should just be a wrapper around ImageIO. However, sometimes Cocoa adds an unexpected layer of thread-unsafety (e.g. NSRunLoop vs. CFRunLoop), and the Cocoa API docs aren't as helpful as the Carbon ones for thread safety.

and each thread has its own graphics
context.  The post I linked to does indicate that you might want to
use [image setCacheMode:NSImageCacheNever].  If your goal is just to
get an NSBitmapImageRep from a file, it's probably easier just to use
+imageRepWithContentsOfFile:.

This could work, but as I need to do pixel level manipulation, I really need to know the exact format of the bitmap and this does not seem to let me
specify it.

That makes sense. You could also introspect the returned imagerep and see if it matches your desired format, then only redraw it if necessary. For messing with pixels, I'd avoid NSImage altogether and just use ImageIO to create a CGImage, then draw that into your NSBitmapImageRep with [[NSGraphicsContext graphicsContextWithBitmapImageRep:] graphicsPort] as the CGContext.

--
adam
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to