簡體   English   中英

如何從照片庫獲取上一張照片的路徑?

[英]How do i get last photo's path from photo library?

我正在使用這種方法進行屏幕捕獲:

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

感謝名單

無法使用以下方法獲取資產網址:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM