2013-11-01 101 views
2

我使用这个方法来进行屏幕捕获:如何从照片库中获取最后一张照片的路径?

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 ]; 

感谢名单

回答

1

有是没有办法得到资产url使用:

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]; 
+0

感谢,但我的图片的网址是:'资产库://asset/asset.JPG ID = 7D636703-8786-465D-B896-A0A67F0B0CCE及EXT = JPG'如何转换它以这种方式'文件:// ...' – AsimNet

+0

@AsimNet:你不能用资产网址来做到这一点。或者将图像存储到文档目录而不是photolibrary –

相关问题