2013-11-01 100 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 –

相關問題