実行時にはどちらが良いかを指定します。 1)サイズ250X120の画像をsqliteに保存します。 2)ドキュメントディレクトリに同じサイズのイメージを保存する。 2つの場所では、これらの保存された画像をコントロールに表示する必要があります。 また、最大20枚の画像を表示する必要があります。実行時に画像をiphoneアプリケーションに保存
0
A
答えて
1
2番目のオプションは、最初のオプションよりはるかに優れています。第二部の使用を達成するには、次の
- (void)saveImage:(UIImage*)image:(NSString*)imageName
{
NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]]; //add our image to the path
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)
NSLog(@"image saved");
}
1
1 M.Sharjeelを - と、私たちが使用して、我々は(携帯電話/パッド上のsqliteに裏打ちされた)コアデータオブジェクトを持っています半ハイブリッド、通常であります検索が高速なファイルに関するメタデータを持っていて、NSStringをdocumentsDirectory内のパスに保存します。
+0
コア・データは、効率的で、SQLiteのより良い実行...彼と一緒に同意します –
0
ドキュメントディレクトリアプローチを使用する場合は、これを行うのが良い方法です。
-(void) saveImage:(UIImage *)image withFileName:(NSString *)imageName ofType:(NSString *)extension inDirectory:(NSString *)directoryPath {
if ([[extension lowercaseString] isEqualToString:@"png"]) {
[UIImagePNGRepresentation(image) writeToFile:[directoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", imageName, @"png"]] options:NSAtomicWrite error:nil];
} else if ([[extension lowercaseString] isEqualToString:@"jpg"] || [[extension lowercaseString] isEqualToString:@"jpeg"]) {
[UIImageJPEGRepresentation(image, 1.0) writeToFile:[directoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", imageName, @"jpg"]] options:NSAtomicWrite error:nil];
} else {
ALog(@"Image Save Failed\nExtension: (%@) is not recognized, use (PNG/JPG)", extension);
}
}
単にこのようにそれを行う、画像を保存するには:
NSString * path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
[self saveImage:yourImage withFileName:@"Your Image Name" ofType:@"png" inDirectory:path];
このメソッドを実装し、画像をロードするには:その後、
-(UIImage *) loadImage:(NSString *)fileName ofType:(NSString *)extension inDirectory:(NSString *)directoryPath {
UIImage * result = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.%@", directoryPath, fileName, extension]];
return result;
}
そして、このようにそれを使用します。
NSString * path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
yourImage.image = [self loadImage:@"Your Image Name" ofType:@"png" inDirectory:path];
または、この方法ではなく、メソッドを作成するので返すものに等しいあなたのイメージ:
NSString * path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
yourImage.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/Your Image Name.png", path]];
関連する問題
- 1. iPhoneアプリケーションに画像を保存
- 2. Iphoneフォトライブラリに画像を保存する
- 3. iPhone - UIImagePickerController - >画像をアプリフォルダに保存
- 4. C#アプリケーションでMySQLに画像を保存
- 5. iPhoneアプリケーションで画像編集を実行するには?
- 6. iPhoneのコアデータに大きなファイル(例:画像/動画)を保存
- 7. Webstorm:保存時に.batを実行
- 8. ギャラリーに画像を保存
- 9. 画像をデータベースに保存
- 10. サーバーに画像を保存
- 11. iphoneデバイスに画像とデータをローカルに保存する方法
- 12. iphoneに.jpg画像を保存するには
- 13. アプリケーションで画像を保存する - android
- 14. iPhoneの「画像を保存」ポップアップを無効にする
- 15. iPhone:特定のフォトアルバムに画像を保存
- 16. iPhoneのUIImageから画像をサンドボックスに保存する
- 17. iPhone:画像/データを「パブリック」フォルダに保存していますか?
- 18. ローカルiphoneのバンドルに画像を保存する方法
- 19. インターネットからiPhoneアプリに画像を保存する
- 20. 保存画像
- 21. 保存画像
- 22. 消しゴム使用時に背景画像を保存する
- 23. 画像の読み込み時にクッキーを保存
- 24. アプリケーション文書に画像を保存する
- 25. iPhone - 画像の操作/編集と保存(高解像度)
- 26. 保存画像アンドロイド
- 27. 最終アプリケーションの実行日時の保存
- 28. 実行中のアプリケーションを保存する
- 29. dbに画像を保存する
- 30. webview Android SDK内に画像を保存
おかげで...私は実装を知っている.... :) – adi27