0

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?

Simon
  • 25,468
  • 44
  • 152
  • 266
Joethemonkey101
  • 45
  • 2
  • 11

1 Answers1

1

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];
Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
ySgPjx
  • 10,165
  • 7
  • 61
  • 78
  • Thanks! That was exactly my question. The only thing is I get 1 error: Too many arguments to function 'UIImagePNGRepresentation'. Here's my code, it's just was what you gave me. – Joethemonkey101 Nov 04 '10 at 14:52
  • NSString *file = @"GameOver Screenshot"; NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *path = [directory stringByAppendingPathComponent:file]; [UIImagePNGRepresentation(image, 1.0) writeToFile:path atomically:YES]; return image; – Joethemonkey101 Nov 04 '10 at 14:52
  • Yeah, sorry; I copy'n pasted the code in your question. It should be `UIImagePNGRepresentation(image)`. The second parameter is only there for `UIImageJPEGRepresentation` (it's the quality parameter). Please consider upvoting/accepting the answer if it helped. Thanks. – ySgPjx Nov 04 '10 at 14:57