gpt4 book ai didi

ios - 如何加载图像到uiimageview

转载 作者:行者123 更新时间:2023-11-29 02:44:22 25 4
gpt4 key购买 nike

如何从自定义文件夹加载图像到uiimageview

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString*ext= [NSString stringWithFormat:@"/Imagenes/30775.png"];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:ext];
//option 1
UIImage * myImage = [UIImage imageWithContentsOfFile: dataPath];
_img.image = myImage
///option 2
UIImageView * myImageView = [[UIImageView alloc] initWithImage: myImage];
_img = myImageView;
///option 3
NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL fileURLWithPath:dataPath]];
_img.image = [UIImage imageWithData:imgData];

我尝试了 3 个选项但都不起作用有什么想法吗?

图像正在从自定义文件夹加载我检查了路径并且是正确的但没有加载

最佳答案

你的路径@"/Imagenes/30775.png"好像是错误的。仔细检查一下。否则以下应该有效

 UIImage * myImage = [UIImage imageWithContentsOfFile: dataPath];
_img.image = myImage

关于ios - 如何加载图像到uiimageview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25334103/

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