开发者

Problems with UIImagePNGRepresentation

开发者 https://www.devze.com 2023-01-23 06:35 出处:网络
I\'m trying to use this line of code [UIImagePNGRepresentation(image, 1.0) writeToFile:pngPath atomically:YES];

I'm trying to use this line of code

 [UIImagePNGRepresentation(image, 1.0) writeToFile:pngPath atomically:YES];

But obviously pngPath is undeclared. So I have to use stringByAppendingPathComponent开发者_如何学运维.

I googled examples of this, and I found this

myPlistPath = [documentsDirectory stringByAppendingPathComponent: 
 [NSString stringWithFormat: @"%@.plist", plistName] ];
[myPlistPath retain]

;

The problem is that I don't have a plist file, because I don't need one. How can I solve all these issues and writeToFile the UIImage image?


I don't fully understand your question, but to get the full path where your file should be saved, you could try this:

NSString *file = @"myfile.png";
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
NSString *path = [directory stringByAppendingPathComponent: file];

and then:

[UIImagePNGRepresentation(image) writeToFile:path atomically:YES];
0

精彩评论

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