How do I save a UIImage to a file?

前端 未结 9 902
抹茶落季
抹茶落季 2020-12-07 13:13

If I have a UIImage from an imagePicker, how can I save it to a subfolder in the documents directory?

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 13:18

    You have to construct a representation of your image as a particular format (say, JPEG or PNG), and then call writeToFile:atomically: on the representation:

    UIImage *image = ...;
    NSString  *path = ...;
    [UIImageJPEGRepresentation(image, 1.0) writeToFile:path atomically:YES];
    

提交回复
热议问题