Reputation:
I'm sending data back and forth through the Bonjour protocol. All the packets are sent as NSData
and usually converted to strings; but what if I need to receive an image? This is the process that will be going on.
NSImage
NSImage
as a NSData
packetNSData
Could I attempt to convert the data into an image and catch the error (which would mean it's not an image)?
Upvotes: 2
Views: 897
Reputation: 160883
Use:
NSImage *image = [[NSImage alloc] initWithData:data];
If data
is not valid image data, then image
will be nil
.
Upvotes: 8