0

当我将该图像提供给它不显示的按钮背景时,我有存储在 iphone 文档目录中的图像文件。

NSString*imageThumbnailVideo= [NSString stringWithFormat:@"%@thumbVideo.png",imageThumbnail];

NSLog(@"imageThumbnailVide is %@",imageThumbnailVideo);

NSString * filePath = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),imageThumbnailVideo];

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
if (fileExists == 0)
{
    NSLog(@"File is Not exists");
}
else 
{
    NSLog(@"File is present");
}

[thumbnailImageView setBackgroundImage:[UIImage imageNamed:imageThumbnailVideo] forState:UIControlStateNormal];

它还显示文件存在但不显示图像。

这是我保存文件的方式

   testT=[NSString stringWithFormat:@"%@thumbVideo",titleTextField.text];

    NSString *newStringVT = [testT stringByReplacingOccurrencesOfString:@" " withString:@""];


    NSString*imageTitleVT=[NSString stringWithFormat:@"%@.png",newStringVT];


    NSString *pathVT = [documentsDirectory stringByAppendingPathComponent:imageTitleVT];


    NSData*thumbVideoData=UIImagePNGRepresentation(thumbnail);

    NSError * error = nil;
    [thumbVideoData writeToFile:pathVT options:NSDataWritingAtomic error:&error];
4

2 回答 2

0
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [path objectAtIndex:0]; 
    NSString *img_path = [documentsDirectory stringByAppendingPathComponent:@"YOUR IMAGE NAME.png"];

    NSURL*   uurl=[NSURL fileURLWithPath:img_path];
[thumbnailImageView setBackgroundImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:uurl]] forState:UIControlStateNormal];
于 2013-10-28T05:49:13.773 回答
0

您可以通过执行以下操作从文件中获取图像:

UIImage* anImage = [UIImage imageWithContentsOfFile:validFilePath];

然后您可以将该图像应用到这样的按钮:

[_someButton setImage:anImage forState:UIControlStateNormal];
于 2013-10-28T05:51:28.310 回答