0

iPhone用のカメラアプリを作成していますが、1つの問題に直面しています。

撮った写真をアプリのプライベート ディレクトリに保存し、写真にカスタム名を付けたい (コードを介して)。たとえば、私は写真を撮り、その写真に mmddyyyyhhmmssXYZ という名前を付けて、その画像を myApp/images ディレクトリに保存したいとします。

これが可能かどうか教えてください。可能であれば、提案やチュートリアルは非常に役に立ちます。

iPhoneアプリの開発は初めてです...私は今、これについて実際に無知です。

ありがとう

4

2 に答える 2

1

これが私のコードです。以下を参照してください。

-(void)copyImagesToCache:(NSString*)imageURl
{

    NSFileManager *filemanager=[NSFileManager defaultManager];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"MyIMages"];

            //now no need to use below single line of code.
//NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"image.png"];
//it just a example here , here you should make a source  path as you pic the images form the camera.

編集: ImagePicker をピックしている間、パスを作成する必要があります。以下の ImagePickerViewControllerDelegate.i のデリゲートを参照してください。

    if(![filemanager contentsOfDirectoryAtPath:folderPath error:nil]){
        [filemanager createDirectoryAtPath:folderPath withIntermediateDirectories:YES attributes:nil error:nil];

    }
    NSString *destPath = [folderPath stringByAppendingPathComponent:@"image1.png"];//here you should create the dynamic name so that you can distinguish all images.
    NSError *err;
  BOOL isCopeid= [filemanager copyItemAtPath:srcPath toPath:destPath error:&err];
  if(isCopeid)
    NSLog(@"Copied");
}


  - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:     (UIImage *)image editingInfo:(NSDictionary *)editingInfo
 { 
  myIMage.image = image;
 //here call the method whcih copy the image to cache
 [self copyImagesToCache: [editingInfo objectForKey:UIImagePickerControllerReferenceURL]]];  
 [here is the link which shown the  editingInfo's keys ][1] 

//remaining code goes here as it is   
}

参考になれば幸いです...!!!!

于 2012-11-14T10:11:01.327 に答える
0

画像をアプリのプライベートディレクトリに書き込む機能-

-(void)writeImagetoPath
 {

    UIImage *myImage = //This is the UIImage you obtained from the camera or the photo library.

    //This is the path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *documentsPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"xyz.png",i]];//You can give any name to the path.

    //Now convert the uiimage to data before writing to file.
    NSData *imgData = UIImagePNGRepresentation(myImage);
    [imgData writeToFile:documentsPath atomically:YES];

}
于 2012-11-14T12:02:10.800 に答える