簡體   English   中英

UImage保存iOS后獲取本地URL

[英]UImage get local url after save ios

我想將圖像保存在相冊中,但是我已經成功保存了圖像,但是現在我想獲取URL(如果我將其傳遞給UIImage ,它將是打開圖像的本地URL)。 由於出現“不允許表達”的錯誤,我無法獲取已保存的圖像網址。 如何在iOS獲取保存的圖像的LOCAL URL

我的嘗試:

-(NSString *) imageSave: (UIImage *)image
{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

        [library writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation completionBlock:^(NSURL *assetURL, NSError *error )
         {
             [library assetForURL:assetURL resultBlock:^(ALAsset *asset )
              {
                  self.temp1 = [NSString stringWithFormat:@"%@",assetURL];
                  NSLog(@"SAVED!");
              }
                     failureBlock:^(NSError *error )
              {
                   self.temp1 = [NSString stringWithFormat:@"NO"];
                  NSLog(@"Error Saving Image!!!");
              }];
         }];

    return self.temp1;
}

我試着做一個屬性,但返回null。

請嘗試遵循可能對您有幫助的代碼。

UIImage *viewImage = YOUR UIIMAGE  // --- 
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];  
// Request to save the image to camera roll  
[library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){  
    if (error) {  
        NSLog(@"error");  
    } else {  
            NSLog(@"url %@", assetURL);
        NSString *myString = [assetURL absoluteString];

    }  
}];  

暫無
暫無

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

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