NSData to UIImage

前端 未结 5 2156
逝去的感伤
逝去的感伤 2020-11-29 08:40

I\'m trying to save a UIIMage and then retrieve it and display it. I\'ve been successful by saving an image in the bundle, retrieving it from there and displaying. My proble

5条回答
  •  孤城傲影
    2020-11-29 09:14

    Just in case this helps someone, from iOS6 we have the imageWithData:scale method. To get an UIImage with the right scale from an NSData object, use that method, declaring the scale you use to store the original image. For example:

    CGFloat screenScale = [[UIScreen mainScreen] scale];
    UIImage *image = [UIImage imageWithData:myimage scale:screenScale];
    

    Here, myimage is the NSData object where you stored the original image. In the example, I used the scale of the screen. If you use another scale for the original image, use that value instead.

提交回复
热议问题