1
A
回答
3
這是用於寫入與用戶指定的名稱
// Create paths to output images
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
// Write a UIImage to JPEG with minimum compression (best quality)
// The value 'image' must be a UIImage object
// The value '1.0' represents image compression quality as value from 0.0 to 1.0
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
// Write image to PNG
[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
// Let's check to see if files were successfully written...
// Create file manager
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
// Point to Document directory
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// Write out the contents of home directory to console
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
1
影像使用委託UIImagePickerControllerDelegate
用於調用照相機或圖像庫中的代碼。
調用攝像頭:
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
isCamera = YES;
[self presentModalViewController:picker animated:YES];
調用庫:
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
[picker setAllowsEditing:YES];
[self presentModalViewController:(UIViewController*)picker animated:YES];
一旦完成,委託方法被調用:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
要寫入圖像庫使用:
UIImageWriteToSavedPhotosAlbum(currentImage, nil, nil, nil);
或將從照片庫中選取的選定圖像保存到UIImage
並對其執行進一步的操作。
相關問題
- 1. 將照片保存到iPhone相冊中的自定義相冊
- 2. 獲取保存到照片相冊的圖像的文件名
- 3. 保存的照片相冊名稱無位置服務權限
- 4. 拍照,並在保存到相冊
- 5. 檢索保存到照片庫的iPhone照片
- 6. 如何允許用戶訪問他們的FB相冊並從他們的相冊中分享圖片
- 7. 在MySql中保存和檢索照片
- 8. 保存帶有照片的字符串並返回它們
- 9. 修改相冊照片的照片
- 10. 移動照片並重命名它們,如果它們存在?
- 11. 將多張照片導入到已保存的照片相冊中
- 12. Facebook API - 檢索我自己的相冊和照片
- 13. 將UIImage保存到照片相冊,然後打開照片應用程序
- 14. 將照片保存爲iPhone從dowloaded NSData對象的相冊
- 15. 保持相機不保存照片
- 16. 檢查是否有名稱的文件存在,並保存相比與其他的名字
- 17. 如何使用iOS9中的PHPhotolibrary在metadat相冊中保存照片?
- 18. 訪問相冊,檢查照片是否已存在
- 19. 將照片保存到DCIM /相機 - 爲什麼他們沒有出現在照片應用程序?
- 20. LibGDX:如何檢索通過相機拍攝並保存在本地的圖片?
- 21. 沒有任何相冊的照片facebook
- 22. 保存照片庫中的照片
- 23. 檢索保存到Blobstore的照片的元數據
- 24. IOS圖片庫獲取給定照片的相冊名稱
- 25. 如何爲保存在照片庫中的照片指定名稱?
- 26. 如何選擇照片,計數照片,併爲每張相冊選擇一張照片?
- 27. 如何檢索Facebook上的照片
- 28. 如何檢索照片的PID?
- 29. 如何列出與PhotoKit共享照片流相冊
- 30. 打開相機,現在添加UIImage從保存的相冊或照片文學
感謝您回覆我的問題。實際上,我需要將照片保存爲具有特定名稱的相冊,而不是文檔目錄。 – Satya