如何将图像从iphone中的文件夹显示到ViewI图像 [英] how to display image from documents folder in of iphone to image ViewI

查看:139
本文介绍了如何将图像从iphone中的文件夹显示到ViewI图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示保存在文档文件夹中的图像问题是它返回文件名但它没有在图像中显示图像查看

I want to display image saved in the documents folder problem is that it returns file name but it does not show image in the image View

 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中

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

这篇关于如何将图像从iphone中的文件夹显示到ViewI图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆