【问题标题】:How do i get last photo's path from photo library?如何从照片库中获取最后一张照片的路径?
【发布时间】:2013-11-01 18:39:29
【问题描述】:

我正在使用这种方法进行屏幕截图:

    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage*theImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(theImage, nil, nil, nil);

我想获取该照片的路径,以便我可以将其与 Instagram 方法一起使用

  NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", lastphotoTaken]];
//    NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", lastphotoTaken]];

self.dic.UTI = @"com.instagram.exclusivegram";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.dic.annotation = [NSDictionary dictionaryWithObject:@"Here Give what you want to share" forKey:@"InstagramCaption"];
[self.dic presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];

感谢

【问题讨论】:

    标签: ios objective-c instagram


    【解决方案1】:

    无法使用以下方法获取资产网址:

    UIImageWriteToSavedPhotosAlbum(theImage, nil, nil, nil);
    

    您可以使用:

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    
    [library writeImageToSavedPhotosAlbum:[theImageCGImage] orientation:(ALAssetOrientation)[theImageimageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){  
        if (error)
        {  
            NSLog(@"Ooops!");  
        }
        else
        {  
            NSLog(@"Saved URL : %@", assetURL);  
        }  
    }];  
    [library release];
    

    【讨论】:

    • 谢谢,但我的图片的网址是:assets-library://asset/asset.JPG?id=7D636703-8786-465D-B896-A0A67F0B0CCE&ext=JPG 如何将其转换为这种方式file://...
    • @AsimNet:你不能用资产网址来做到这一点。或者将图像存储到文档目录而不是照片库
    猜你喜欢
    • 1970-01-01
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    相关资源
    最近更新 更多