gpt4 book ai didi

iphone - 如何在 iPhone 中显示从 URL 下载的图像?

转载 作者:行者123 更新时间:2023-11-28 23:13:42 24 4
gpt4 key购买 nike

我正在从网址下载图片并保存。当我尝试使用 ImageView 在 UI 中显示相同的图像时,我无法做到这一点。所以请建议我需要在以下代码中进行哪些更改。

谢谢。

{

NSLog(@"Downloading...");

UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.objectgraph.com/images/og_logo.png"]]];

NSLog(@"%f,%f",image.size.width,image.size.height);

NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSLog(@"%@",docDir);

NSLog(@"saving png::::%@", docDir);
NSString *pngFilePath = [NSString stringWithFormat:@"%@/test.png",docDir];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
[data1 writeToFile:pngFilePath atomically:YES];

NSString *sss = [docDir stringByAppendingString:@"/test.png"];

imageView1.image = [UIImage imageNamed:sss];

NSLog(@"------%@",sss);

[image release];

}

最佳答案

UIImage *theUIimage = [UIImage imageNamed:sss];
image = [[UIImageView alloc] initWithImage:theUIimage];
[imageView1 addSubview:image];

关于iphone - 如何在 iPhone 中显示从 URL 下载的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7318799/

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