开发者

How to convert data to image in iOS

开发者 https://www.devze.com 2022-12-13 16:44 出处:网络
NSData *imageData = UIImagePNG开发者_运维技巧Representation(your_image_here); After that i transferred it to another iPhone using bluetooth.
NSData *imageData = UIImagePNG开发者_运维技巧Representation(your_image_here);

After that i transferred it to another iPhone using bluetooth. Now i need to convert the data back to image. Can any one tell me how to do it?


I assume this is to et back the data which you encoded in the previous question. For converting UIImage to NSData ,

NSData* pictureData = UIImagePNGRepresentation(image);

To get it back,

UIImage *image = [[UIImage alloc]initWithData:pictureData];

Remember to add [image release] at the end.

or you can use

UIImage *image = [[UIImage alloc]init];
[image imageWithData:pictureData];


In swift-3 : Data is converted back to image by :--

        func compressImage() -> UIImage {
        let imageData = UIImageJPEGRepresentation(UIImage(named:"background.jpg")!, 0.2)
        let image = UIImage(data: imageData!)
        return image!
        }


Just call imageWithData: or on instantiation, you can call initWithData:


[UIImage imageWithData:(NSData *)data];
0

精彩评论

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

关注公众号