如何將具有我選擇的文件名的圖像(如使用UIImageWriteToSavedPhotosAlbum()方法)保存到私有/ var文件夾?UIImage使用iPhone上的文件名保存圖像
12
A
回答
17
肯尼,你有答案!爲了說明,我總是認爲代碼更有幫助。
//I do this in the didFinishPickingImage:(UIImage *)img method
NSData* imageData = UIImageJPEGRepresentation(img, 1.0);
//save to the default 100Apple(Camera Roll) folder.
[imageData writeToFile:@"/private/var/mobile/Media/DCIM/100APPLE/customImageFilename.jpg" atomically:NO];
10
UIImageWriteToSavedPhotosAlbum()
僅用於保存到照片相機膠捲。要保存到自定義文件夾,您需要將UIImage轉換爲帶有UIImageJPEGRepresentation()
或UIImagePNGRepresentation()
的NSData,然後將此NSData保存到您喜歡的任何位置。
+0
肯尼,謝謝。 +1 – erastusnjuki 2010-02-16 02:57:06
0
您可以使用下面的代碼,而無需使用ALAssetsLibrary的...
NSString *fileName;
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:^{
if([picker sourceType] == UIImagePickerControllerSourceTypeCamera)
{
UIImageWriteToSavedPhotosAlbum(image,nil, nil, nil);
[self performSelector:@selector(GetImageName) withObject:nil afterDelay:0.5];
}
else
{
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[refURL] options:nil];
fileName = [[result firstObject] filename];
}
}];
-(void)GetImageName
{
NSString *str [email protected]"";
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
if (fetchResult != nil && fetchResult.count > 0) {
str = [[fetchResult lastObject] filename];
}
fileName = str;
}
相關問題
- 1. 保存的UIImage爲PNG在iPhone上
- 2. 在iPhone中使用較少的內存,uiimage和圖像內容的文件
- 3. 從iPhone的UIImage將圖像保存到沙盒中
- 4. iphone圖像保存
- 5. iPhone保存圖像
- 6. 使用Javascript禁用iPhone上的「保存圖像」菜單
- 7. 使用休眠保存圖像文件
- 8. 使用SqlDataSource保存圖像文件
- 9. 使用UIImagePickerController在設備上保存圖像並保存圖像
- 10. 使用NSData保存PNG圖像writetofile保存iphone磁盤上的損壞數據
- 11. 用我自己的名字保存UIImage?
- 12. 在iPhone上保存圖像和圖像的信息
- 13. 是否可以在iPhone上使用Core Graphics保存圖像?
- 14. 如何在上傳並保存文件夾時使用java chage圖像名稱?
- 15. iPhone - UIImagePickerController - >將圖像保存到應用程序文件夾
- 16. 保存圖像到文件
- 17. xamarin.forms保存文件/圖像
- 18. PHP保存圖像文件
- 19. 簡單的Django圖像上傳 - 圖像文件沒有保存
- 20. 如何在iphone上保存谷歌地圖上的圖像
- 21. 使用JAVA上傳圖像並保存在文件夾中
- 22. iPhone:如何獲取使用UIImageWriteToSavedPhotosAlbum()保存的圖像的文件路徑?
- 23. 如何在Iphone上保存帶空格的文件名
- 24. 在MATLAB中使用不同文件名批量保存圖像文件
- 25. 如何在iPhone上調整圖像大小並保存圖像?
- 26. 如何將圖像保存到文件中並使用MVC3將圖像名稱保存到數據庫?
- 27. 如何使用objective-C將圖像保存到iphone的Wallpaper文件夾中?
- 28. 禁用iPhone「保存圖像」彈出
- 29. 圖像保存到iPhone應用程序
- 30. 使用保存到內存流的圖像導出文件
保存到文檔文件夾的示例 NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString * documentsDirectory = [paths objectAtIndex:0]; NSString * filePath2 = [NSString stringWithFormat:@「%@ /%@。jpg」,documentsDirectory,fileName]; NSData * imageData = UIImageJPEGRepresentation(drawImage.image,1.0); [imageData writeToFile:filePath2 atomically:NO]; – 2010-11-21 23:31:24
[imageData writeToFile:@「/ private/var/mobile/Media/DCIM/100APPLE/customImageFilename.jpg」原子地:NO];什麼是私人/ var/mobile文件夾? 這是一個標準的地方寫出一個文件在iOS? – user798719 2011-08-01 22:58:37
問題是,如果蘋果將允許使用該代碼的應用程序... http://stackoverflow.com/questions/2884003/will-the-app-get-rejected-if-you-write-image-to-private -var-mobile-media-dcim-1?lq = 1 – 2013-01-24 10:24:21