回答
是的,你可以在文件目錄中保存的圖像,並保留圖像文件名在後之後的數組從doc檢索圖像。 DIR。就像這樣
// For error information
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/YOUR_IMG_FOLDER"];
if (![fileMgr fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder
//Get the current date and time and set as image name
NSDate *now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd_HH-mm-ss";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSString *gmtTime = [dateFormatter stringFromDate:now];
NSLog(@"The Current Time is :%@", gmtTime);
NSData *imageData = UIImageJPEGRepresentation(_postImage, 0.5); // _postImage is your image file and you can use JPEG representation or PNG as your wish
int imgSize = imageData.length;
////NSLog(@"SIZE OF IMAGE: %.2f Kb", (float)imgSize/1024);
NSString *imgfileName = [NSString stringWithFormat:@"%@%@", gmtTime, @".jpg"];
// File we want to create in the documents directory
NSString *imgfilePath= [dataPath stringByAppendingPathComponent:imgfileName];
// Write the file
[imageData writeToFile:imgfilePath atomically:YES];
**// Keep your Image file name into an mutable array here OR you can saved the array in a UserDefaults**
然後從文檔中檢索。 DIR。從迭代數組。
//Get image file from sand box using file name and file path
NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"YOUR_IMG_FOLDER"];
stringPath = [stringPath stringByAppendingPathComponent:imgFile]; // imgFile to get from your array, where you saved those image file names
UIImage *image = [UIImage imageWithContentsOfFile:stringPath];
謝謝你......快樂的編碼。
謝謝你作爲答覆 –
你可以解釋一下,請不要混淆如何添加圖像一個一個地排列如何顯示在桌面視圖 –
你是捕捉圖像或從服務器獲取??? –
您可以保存圖像NSUserDefaults的如下,
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
if(!self.phto_arr_)
{
self.phto_arr_ = [[NSMutableArray alloc] init];
}
[self.phto_arr_ addObject: chosenImage];
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:self.phto_arr_];
[[NSUserDefaults standardUserDefaults] setObject: encodedObject forKey:@"images"];
[[NSUserDefaults standardUserDefaults] synchronize];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
謝謝你的重播 –
你是最歡迎 –
嘗試下面這段代碼: 假設你要像名字也顯示使用此代碼,
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
chosenImage = info[UIImagePickerControllerOriginalImage];
chosenImage = [UIImage unrotateImage:chosenImage];
addGalleryImageview.image = chosenImage;
isCameraOn = YES;
NSString* fileName = [NSString stringWithFormat:@"gallery%@",[Utils getDateString]];
imageNamelbl.text = fileName;
[picker dismissViewControllerAnimated:YES completion:NULL];}
- (UIImage*)unrotateImage:(UIImage*)image{
CGSize size = image.size;
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0,0,size.width ,size.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;}
- 1. 問題採摘圖像從畫廊
- 2. GIT櫻桃採摘如何找出已經採摘櫻桃
- 3. Ray gluingProject()採摘
- 4. LWJGL 3D採摘
- 5. GLScene採摘
- 6. 3D採摘lwjgl
- 7. 採摘從
- 8. 採摘熱鍵
- 9. 試圖保存圖像採摘到appdocs - 沒有發生
- 10. 採摘從畫廊和展示照片的圖像視圖
- 11. IOS GLKit:圖靈GLKViewDrawableMultisample4X停止對象採摘
- 12. 如何櫻桃採摘交互
- 13. Ruby on Rails的 - 如何採摘和update_all
- 14. 如何採摘hstore鍵與ActiveRecord的
- 15. 圖像摘錄如下PHP
- 16. 我在採摘嗎?
- 17. Android OpenGL 3D採摘
- 18. LWJGL的3D採摘
- 19. OpenTK鼠標採摘
- 20. 相片挑選,採摘後,圖像太大
- 21. 有人可以告訴我它從哪裏採摘圖像?
- 22. 應用程序在採摘圖像時崩潰
- 23. Android不採摘Facebook顯示圖片
- 24. 如何採取全圖的mapbox IOS SDK
- 25. 如何添加攝像頭採集的圖像在陣列中的IOS
- 26. 如何在圖像中採樣顏色
- 27. 如何上傳圖像採用了android
- 28. 如何獲得symfony的採集圖像
- 29. Eclipse沒有采摘oracle.jdbc.OracleDriver
- 30. Git櫻桃採摘範圍
只需保存圖像在目錄中唯一的名稱,商店的獨特的名稱爲數組,並從目錄檢索圖像,顯示在你的tableview中。如果你想答案然後我會發布它 –
如果你想保存圖像的默認照片庫,然後使用.. https://stackoverflow.com/a/44328085/5315917 –