【发布时间】:2013-06-25 15:34:29
【问题描述】:
我正在使用核心数据来保存我的应用程序中包含的一组图像的文件名。
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
// app already launched
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
// This is the first launch ever
NSArray *mainDishImages = [NSArray arrayWithObjects:@"egg_benedict.jpg", @"full_breakfast.jpg", @"ham_and_cheese_panini.jpg", @"ham_and_egg_sandwich.jpg", @"hamburger.jpg", @"instant_noodle_with_egg.jpg", @"japanese_noodle_with_pork.jpg", @"mushroom_risotto.jpg", @"noodle_with_bbq_pork.jpg", @"thai_shrimp_cake.jpg", @"vegetable_curry.jpg", nil];
NSArray *drinkDessertImages = [NSArray arrayWithObjects:@"angry_birds_cake.jpg", @"creme_brelee.jpg", @"green_tea.jpg", @"starbucks_coffee.jpg", @"white_chocolate_donut.jpg", nil];
for (NSString *imagePath in mainDishImages) {
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *newRecipe = [NSEntityDescription insertNewObjectForEntityForName:@"Recipe" inManagedObjectContext:context];
[newRecipe setValue:imagePath forKey:@"imageFilePath"];
}
for (NSString *imagePath in drinkDessertImages) {
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *newRecipe = [NSEntityDescription insertNewObjectForEntityForName:@"Deserts" inManagedObjectContext:context];
[newRecipe setValue:imagePath forKey:@"imageFilePath"];
}
}
但我也允许用户通过使用设备相机拍照来添加项目。如何保存图像以便我的应用可以再次使用它,并将其集成到我现有的核心数据方案中?
谢谢
【问题讨论】:
-
您需要全分辨率图像吗?例如,在我正在开发的应用程序中,我需要图像,但我不需要更高的分辨率,因此我将它们作为压缩图像 (jpeg) 存储在 Core Data 中。它运作良好,我不必处理外部参考。如果您必须拥有完整的分辨率,那么您几乎需要将其存储在文件系统中并对其进行引用。
-
优先保存完整分辨率,因为该应用将允许用户稍后将图像上传到 facebook,并且还会调整图像大小以在 UICollectionView 和详细视图中使用。
标签: ios objective-c image uiimagepickercontroller save