これは、画像をメールに添付する方法の2つの基本的な例です。
// with UIImage * image;
MFMailComposeViewController * mfcvc = [[[MFMailComposeViewController alloc] init] autorelease];
NSData * imageData = UIImagePNGRepresentation(image);
[mfcvc addAttachmentData:imageData mimeType:@"image/png" fileName:@"demo"];
[self.viewController presentModalViewController:mfcvc animated:YES];
// with UIImage * image; and float compression_quality; between 0.0 and 1.0
MFMailComposeViewController * mfcvc = [[[MFMailComposeViewController alloc] init] autorelease];
NSData * imageData = UIImageJPEGRepresentation(image, compression_quality);
[mfcvc addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"demo"];
[self.viewController presentModalViewController:mfcvc animated:YES];
アプリのサンドボックスのドキュメントディレクトリに画像を保存するには
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
NSString *png = @".png";
NSString *filename = [drawquestion stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *imagePath = [documentDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%@",filename, png]];
[imageData writeToFile:imagePath atomically:YES];
PS
パスの構成をクリーンアップしました。コードに次のようなパスがあるようです。
/var/mobile/Applications/APP_ID//var/mobile/Applications/APP_ID/Documents/filename.png