简体   繁体   English

如何显示从文档目录到图像视图的图像?

[英]How can i display images from document directory to image view?

I want to display my images from document directory... i got the contents of directory. 我想显示文档目录中的图像...我得到了目录的内容。 but when i want to display image, it display nothing... I checked in document directory.. there are images.. but don't know why it is not displaying in UIimage view??? 但是当我想显示图像时,它什么也不显示...我在文档目录中签到了。

can anybody help me??? 有谁能够帮助我??? where is the problem??? 问题出在哪儿???

MY code 我的密码

NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:newDir  error:nil];
setImage.image = [UIImage imageWithContentsOfFile:[filePathsArray objectAtIndex:0]];

Hey i got the answer..... Please follow this link 嘿,我得到了答案.....请点击此链接

here 这里

Thanx to everyone for their precious help........ 感谢每个人的宝贵帮助........

I think you are confusing UIImage with UIImageView . 我认为您将UIImageUIImageView混淆了。 After creating your UIImage setImage, you need to set it to a UIImageView: 创建UIImage setImage之后,需要将其设置为UIImageView:

UIImageView *myImageView = [[UIImageView alloc] initWithImage:setImage];

then you need to add the myImageView to your view: 那么您需要将myImageView添加到您的视图中:

[self.view addSubview:myImageView];

EDIT : 编辑

to check for if the file exists at a path you use fileExistsAtPath and log the output: 检查文件是否存在于您使用fileExistsAtPath的路径并记录输出:

if ([[NSFileManager defaultManager] fileExistsAtPath:myPath]) {

     NSLog(@"file exists!");
}

myPath would be the NSString for the path you are obtaining. myPath将是您要获取的路径的NSString。 I think most likely that you are not getting the path to the file correctly. 我认为您很可能没有正确获取文件的路径。 Are you sure the images are in the documents directory? 您确定图像在文档目录中吗? if you are using the simulator you can always use finder to locate the files and folders inside your app's sandbox. 如果您使用的是模拟器,则始终可以使用finder查找应用程序沙箱中的文件和文件夹。 try to look your images up manually by going to 尝试通过以下方法手动查找图像

 ~/Library/Application Support/iPhone Simulator/x.x/Applications/

hope this helps. 希望这可以帮助。

Use this code.. 使用此代码。

NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );

NSString *docDirectory = [sysPaths objectAtIndex:0];

NSString *imagePath=[docDirectory stringByAppendingPathComponent:@"your image-name"];

UIImageView *myimage=[UIImageView alloc] initWithFrame:CGRectMake(0,0,20,20)];
myimage.image=[UIImage imageWithData:[NSData dataWithContentsOfFile:imagePath]];    
[self.view addSubView:myimage];
[myimage release];

may this will help you... 可以帮助您...

If your image in the document directory use following: 如果您的图像在文档目录中,请使用以下命令:

NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *newPath = [directory stringByAppendingPathComponent:@"myMovie.m3u8"];
    UIImage *image=[UIImage imageWithContentsOfFile:newPath];

You have used path for document directory but not provided path for image stored there.. check following here 您已使用文档目录路径,但未提供存储图像的路径。

NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:newDir  error:nil];
setImage.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/imageName.png", [filePathsArray objectAtIndex:0]]];

Try this, 尝试这个,

NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:newDir  error:nil];
NSString *str_imgpath = [NSString stringWithFormat:@"%@/imageName.png", [filePathsArray objectAtIndex:0]]
imgView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:str_imgpath]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Iphone:如何在图像视图中显示文档目录图像? - Iphone : How to Display Document Directory images in Image View? 从文档目录在webview中以html显示图像 - display image in html in webview from document directory 我如何在表格视图的顶部显示新图像 - how can i display new images at the top of the table view 当我在滚动UITableview期间显示文档目录中的图像时,内存不断增加然后应用程序崩溃 - Memory continuously increase then app crash when i display image from document directory during scrolling UITableview 如何播放文档目录中的视频(按名称)? - How can i play video (By Name) from document directory ? 如何显示NSDocument目录中的所有图像 - How to display all images from NSDocument directory 我如何从网址显示图像? - how can i display image from url? 如何从我的iPhone App文档目录中选择所有图像 - How to select all the images from my iPhone App document directory 如何创建图像的网格视图?单击图像时,应打开该图像 - How can I create grid view of images? On click of a image it should open that image 如何获取iphone ipod播放列表图像并在图像视图中显示它 - how to get iphone ipod playlist images and display it in image view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM