1

保存された画像の名前をカメラから取得する方法を検索しましたが、簡単なものが見つかりませんでした。

これは私のコードです:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
if( [picker sourceType] == UIImagePickerControllerSourceTypeCamera){
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [library writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation completionBlock:^(NSURL *assetURL, NSError *error )
     {
         NSLog(@"IMAGE SAVED TO PHOTO ALBUM");
         [library assetForURL:assetURL resultBlock:^(ALAsset *asset )
          {
              NSLog(@"we have our ALAsset!");
              NSLog(@"%@", assetURL);

          }
                 failureBlock:^(NSError *error )
          {
              NSLog(@"Error loading asset");
          }];
     }];
}

}

私はあなたが答えを持っている、私はそれをテストさせていただきます.

前もって感謝します。

4

2 に答える 2

1
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *resourceURL;
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *image =[[UIImage alloc] init];

image =[info objectForKey:@"UIImagePickerControllerOriginalImage"];

NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"];

NSString *imageName = [imagePath lastPathComponent];

resourceURL = [info objectForKey:UIImagePickerControllerReferenceURL];


NSData *imageData;
NSString *extensionOFImage =[imageName substringFromIndex:[imageName rangeOfString:@"."].location+1 ];

if ([extensionOFImage isEqualToString:@"jpg"])
{
    imageData =  UIImagePNGRepresentation(image);
}

else
{
    imageData =    UIImageJPEGRepresentation(image, 1.0);
}

int imageSize=imageData.length/1024;
    NSLog(@"imageSize--->%d", imageSize);
if (imageName!=nil) {
   NSLog(@"imageName--->%@",imageName);
}
else
{
   NSLog(@"no image name found");
}
}

ASSert を使用している場合

-(void)assetPickerController:(WSAssetPickerController *)sender didFinishPickingMediaWithAssets:(NSArray *)assets
{
[self dismissViewControllerAnimated:YES completion:^{

    if (assets.count < 1) return;

    //self.pageControl.numberOfPages = assets.count;

    int index = 0;

    for (ALAsset *asset in assets) {
        //  NSString *imageName = [[asset defaultRepresentation] filename];

        UIImage *image = [[UIImage alloc] initWithCGImage:asset.defaultRepresentation.fullScreenImage];
        // (@"%@", [[asset defaultRepresentation] filename]);
        NSData *imageData = UIImagePNGRepresentation(image);
        int imageSize=imageData.length/1024;
    (either)    
   NSURL *imagePath = [asset objectForKey:@"UIImagePickerControllerReferenceURL"];
    //  NSURL *imagePath = [NSURL URLWithString:[asset ob]];
         NSString *imageName = [imagePath lastPathComponent];
    (or)
    NSLog(@"%@",[[asset defaultRepresentation] filename]);
        index++;
    }

}];
}
于 2013-12-23T11:30:06.880 に答える