程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-iPhone-從文件夾中顯示圖片

ios-iPhone-從文件夾中顯示圖片

編輯:編程綜合問答
iPhone-從文件夾中顯示圖片

顯示保存在文件夾中的圖片。只返回了文件名字,沒顯示。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];  
            NSString*patientlastName;    
            NSString*test=@"nicej";
           patientlastName=[test stringByReplacingOccurrencesOfString:@" " withString:@""];
        NSString * filePath = [NSString stringWithFormat:@"%@/Documents//%@.png", NSHomeDirectory(),patientlastName];
        BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
        if (fileExists == 0) 
        { 
            NSLog(@"File is Not exists");
            appDelegate.imageURL=@"File Not Exists";
        }
        NSString *userfile=[NSString stringWithFormat:@"%@",patientlastName];
        appDelegate.imageURL=userfile;

           PictureDisplayViewController *targetController = [[PictureDisplayViewController alloc] initWithNibName:@"PictureDisplayViewController" bundle:nil];
        targetController.modalPresentationStyle = UIModalPresentationFullScreen;
        [self.splitViewController presentViewController:targetController animated:YES completion:nil];

PictureDisplayViewController中:

       imageView.image=[UIImage imageNamed:@"nicej.png"];

最佳回答:


保存圖片路徑:

 NSFileManager *fileMan = [NSFileManager defaultManager];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *str= [NSString stringWithFormat:@"%@.png",patientlastName];
   NSString *Image_filePath=[documentsDirectory stringByAppendingPathComponent:str];
 NSData *imagedata=UIImagePNGRepresentation(yourimage);
 [fileMan createFileAtPath:[Image_filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] contents:imagedata attributes:nil];

獲取圖片路徑:

NSString* fileName = [NSString stringWithFormat:@"%@.png",patientlastName}
        NSArray *arrayPaths =
        NSSearchPathForDirectoriesInDomains(
                                            NSDocumentDirectory,
                                            NSUserDomainMask,
                                            YES);
        NSString *path = [arrayPaths objectAtIndex:0];
        NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];   
      UIImage *image1=[UIImage imageWithContentsOfFile:pdfFileName];
   imageView.image=image1;
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved