gpt4 book ai didi

iphone - UIImageView - 显示目录中的图像

转载 作者:行者123 更新时间:2023-12-03 20:22:29 24 4
gpt4 key购买 nike

我有以下代码:

- (void)viewDidLoad {
NSString *homeDirectoryPath = NSHomeDirectory();
NSString *imagePath = [homeDirectoryPath stringByAppendingString:@"/graph.png"];
NSLog(@"Image: %@", imagePath);

if (![[NSFileManager defaultManager] fileExistsAtPath:imagePath isDirectory:NULL])
{
graph = imagePath;
//[[NSFileManager defaultManager] createDirectoryAtPath:imagePath attributes:nil];
}

'graph' 被定义为 UIImageView。我正在尝试显示路径“imagePath”中的文件。我知道代码 graph = imagePath 不正确,因为变量“imagePath”声明它包含图像的路径。

如何显示位于特定图像路径的图像?

问候,斯蒂芬

最佳答案

您必须创建一个 imageview 对象,将其设置为 ImageView 的图像并释放您创建的图像:

UIImage *graphImage = [[UIImage alloc] initWithContentsOfFile: imagePath];
graph.image = graphImage;
[graphImage release];

关于iphone - UIImageView - 显示目录中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3448508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com