参考サイト
[XCODE] iPhoneで画像をアプリケーション内に保存するには – YoheiM .NET
UIImage document保存, 取得 – Ryusuke Fuda’s Tech Blog
UIImageの画像データをPNGファイルに保存する方法 – 強火で進め
UIImagePNGRepresentationと、
writeToFile: atomically: ってとこがキモかな。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
-(void)sharedFileSave:(UIImage *)sender { NSLog(@"しぇあどふぁいるせーぶ"); //保存する画像をPNGでnsdataに変換? UIImage *image = sender; NSData *data = UIImagePNGRepresentation(image); //ドキュメントフォルダ(共有フォルダ)のパスの取得 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *DocumentsDirPath = [paths lastObject];//これがパスになるらしい。 //保存する名前を決める。 NSString *exportFilename = @"sample2.png"; //保存先のパスと名前を合体させたパスを作成。 NSString *exportFilePath = [DocumentsDirPath stringByAppendingPathComponent:exportFilename]; ; if ([data writeToFile: exportFilePath atomically:YES]) { NSLog(@"ほぞんOK"); } else { NSLog(@"ほぞんError"); } } |