Re: Creating NSImage with NSData
Re: Creating NSImage with NSData
- Subject: Re: Creating NSImage with NSData
- From: Mark Woollard <email@hidden>
- Date: Mon, 15 Mar 2004 12:31:12 +0000
Yes, have found that if I load the data into an NSBitmapImageRep, the
rep parses the data correctly and I can then add the rep to an NSImage
instance. Just thought that bit would be done by NSImage.
Thanks
Mark
On 15 Mar 2004, at 11:53, Robert Cerny wrote:
Hi,
- (id)initWithData:(NSData *)data
Initializes the receiver, a newly allocated NSImage instance, with the
contents of the data object data. If initWithData: is able to create
one or more image representations, it returns self. Otherwise, the
receiver is freed, and nil is returned.
if you're getting nil, it means that the NSImage cannot be created
using known representations. You need to create the representation
manually and than init NSImage from it.
HTH
Robert
On 15.3.2004, at 11:24, Mark Woollard wrote:
I have a jpg of image data extracted from part of a file. I thought I
should be able to create an NSImage directly from this data as
follows:
NSData *data = [NSData dataWithBytes:p length:len];
m_image = [[NSImage alloc] initWithData:data];
Where p is a pointer to the data buffer and len the length of the
data.
However, m_image is null after the code is executed. I have added test
code to write out the NSData buffer to file and the resulting file can
be opened and displayed just as any other jpg image on the system, so
I
conclude the code extracting the image from the file in question is
OK,
and the buffer contains a valid jpg. Am I mis-understanding what
initWithData does?
Thanks
Mark
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.