Re: help with NSImage
Re: help with NSImage
- Subject: Re: help with NSImage
- From: Heinrich Giesen <email@hidden>
- Date: Sun, 13 Feb 2005 10:54:20 +0100
On 12.02.2005, at 16:57, Daniel O'Sullivan wrote:
hi,
I'm a new to cocoa so this will probably sound rather basic, but i'm
looking
to display .ppm images using NSImage. Do i use NSQuickDrawView? if
anyone
could help me, it would be really appreciated especailly if theres any
example code out there that i could view.
On 12.02.2005, at 14:14:30 +0100, Uli Kusterer answered:
I don't think Cocoa or QuickTime support loading pbm and ppm images
yet. IIRC, PPM is this text-based file format that uses numeric
strings to encode each pixel, right?
No, this is only true for the seldom used formats P1, P2 and P3.
In that case, your best bet is to use NSString
-stringWithContentsOfFile: to load the PPM, and then to parse that
No, never, you should always use NSData!
The formats P4, P5, P6 and P7 contain raw (binary) data, which are very
similar to the data structure of an NSBitmapImageRep.
To create an NSImageRep from pbm data is a relatively simple job.
Here <http://www.heinrich-giesen.homepage.t-online.de/MacOSX/>
in Archive.zip I offer you some files from one of my applications.
PBMImageRep is a subclass of NSBitmapImageRep and registers itself at
NSImageRep with: [NSImageRep registerImageRepClass:[self class]];
So you can write:
id aRep = [NSImageRep imageRepWithContentsOfFile:pbmFileName];
or test if it works with pbm data:
BOOL rtn = [NSImageRep canInitWithData:[NSData dataWithContentsOfFile:
pbmFileName]];
If you then really need an NSImage, create one:
NSImage *img = [[NSImage alloc] initWithSize:NSZeroSize];
[img addRepresentation:aRep];
--
Heinrich Giesen
email: email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden