开发者

Using NSKeyedArchiver and NSData to send UIImage over bluetooth

开发者 https://www.devze.com 2022-12-19 08:51 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号