Question

I was wondering if it is possible to send a UIImage over bluetooth after encoding it into a NSMutableData using NSKeyedArchiver. This is what I had in mind:

NSMutableData *data = [[NSMutableData alloc] init];

NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:[UIImage imageNamed:"test.png" forKey:kImageKey];

[archiver finishEncoding];
Was it helpful?

Solution

You cannot archive UIImage instances like that. You will have to create an external representation first, like PNG or JPG. You can do that with for example the UIImagePNGRepresentation() function. It will return an NSData instance containing the compressed image in PNG format. That NSData instance can be used with NSArchiving.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top