Re: How do I convert data in NSString to NSImage
Re: How do I convert data in NSString to NSImage
- Subject: Re: How do I convert data in NSString to NSImage
- From: Chris Ridd <email@hidden>
- Date: Wed, 10 Sep 2003 08:47:32 +0100
On 10/9/03 8:23 am, Ivan Myrvold <email@hidden> wrote:
>
Got it working this way:
>
>
NSString *picstr; // the string with jpeg data
>
NSData *picdata = [NSData dataWithBytes:[picstr cString] length:[picstr
>
cStringLength]]; // now picdata contains the jpeg data
>
NSImage *myPicture = [[NSImage alloc] initWithData:picdata]; // now we
>
have the NSImage
That's only going to work by luck, isn't it?
Since any JPEG is quite likely to have a NUL byte somewhere inside it,
[picstr cStringLength] is going to return a "too short" value. The value
you're passing for length probably doesn't really matter, but if NSData
starts to copy stuff around, you're going to lose.
Conversely, if the JPEG *doesn't* have a NUL byte inside it, [picstr
cStringLength] is going to walk off reading unallocated memory and possibly
crash your app :-(
How exactly did you read the JPEG into an NSString in the first place? Is it
possible to read it into a more appropriate data structure?
Cheers,
Chris
_______________________________________________
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.