पर फ़ाइल नाम के साथ UIImage सेविंग छवि मैं एक छवि को कैसे सहेज सकता हूं (जैसे UIImageWriteToSavedPhotosAlbum() विधि का उपयोग करना) मेरी पसंद के फ़ाइल नाम के साथ निजी/var फ़ोल्डर में?आईआईएम
Q
आईआईएम
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 को NS12ata में UIImageJPEGRepresentation()
या UIImagePNGRepresentation()
के साथ कनवर्ट करने की आवश्यकता है, फिर इस NSData को कहीं भी कहीं भी सहेजें।
+0
केनी, धन्यवाद। +1 – erastusnjuki
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;
}
दस्तावेज़ फ़ोल्डर NSArray * पथ = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) में नमूना बचत; एनएसएसटींग * दस्तावेज डायरेक्टरी = [पथ ऑब्जेक्टएंड इंडेक्स: 0]; एनएसएसटींग * filePath2 = [एनएसएसटींग स्ट्रिंगविथफॉर्मैट: @ "% @ /% @। Jpg", दस्तावेज़ निर्देशिका, फ़ाइल नाम]; एनएसडीएटा * imageData = UIImageJPEGRresentation (drawImage.image, 1.0); [imageData लिखने के लिए फ़ाइल: फ़ाइलपैथ 2 परमाणु रूप से: नहीं]; –
[imageData लिखने के लिए फ़ाइल: @ "/ निजी/var/मोबाइल/मीडिया/डीसीआईएम/100APPLE/customImageFilename.jpg" परमाणु रूप से: नहीं]; यह निजी/var/मोबाइल फ़ोल्डर क्या है? क्या यह आईओएस में एक फाइल लिखने के लिए एक मानक जगह है? – user798719
सवाल यह है कि, यदि सेब उस कोड के साथ किसी ऐप को अनुमति देगा ... http://stackoverflow.com/questions/2884003/will-the-app-get-rejected-if-you-write-image-to-private -var-mobile-media-dcim-1? lq = 1 –