I was wondering if it is possible 开发者_如何学Cto 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];
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.
精彩评论