这个初始化有什么问题

时间:2011-05-04 07:01:27

标签: iphone ipad

我想在像这样的路径中加载带图像的uimage

/ var / mobile / Applications / 429E283A-6E89-4BCE-861F-252C5327F711 / Library / Application Support / Students / 43y。 F./1.2.840.113564.3.1.2.180.0.0.90.20081228203734483950/1.2.840.113564.10.1.226230117146661685815524478531105858244/Thumbnail.bmp

我使用了以下代码

UIImage* theImage = [UIImage imageNamed:ThumbnailPath];

if (theImage !=nil) {

        cell.imageView.image = theImage;

}
else {

    NSLog(@"Error");
}

其中ThumbnailPath是路径 但uiimage总是零,我相信文件存在,任何人都可以帮我修复

祝你好运

5 个答案:

答案 0 :(得分:2)

UIImage* theImage = [UIImage imageWithContentsOfFile:ThumbnailPath];

if (theImage !=nil) {

        cell.imageView.image = theImage;

}
else {

    NSLog(@"Error");
}

希望这会有所帮助

答案 1 :(得分:0)

我不喜欢UIImage imageNamed可以从.bmp文件加载...阅读thisthis SO线程来处理iphone中的.bmp文件

答案 2 :(得分:0)

请参阅UIImage class了解加载图片。

答案 3 :(得分:0)

你如何获得“ThumbnailPath”的价值 你在NSBundle类下使用+ pathForResource:ofType:inDirectory:方法吗? 如果不考虑使用它。 如果是,请编辑您的问题,并在代码中包含您为ThumbnailPath设置值的部分。

答案 4 :(得分:0)

可能这可以帮到你

+(UIImage*)getImageFromDocumentDirectoryWithName:(NSString*)imageName
{
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    NSString *aPath= [documentsDir stringByAppendingPathComponent:imageName];
    UIImage *myimage=nil;
    NSFileManager *fileManager = [NSFileManager defaultManager];

    if([fileManager fileExistsAtPath:aPath])
    {
        myimage =[UIImage imageWithContentsOfFile:aPath];
    }

    return myimage;
}

您可以在所需的课程中添加此功能,并相应地使用它

相关问题