我有一些图片需要从网上获取。仅使用来自 URL 的数据。
它们需要在 Retina 显示屏上正确显示。
当我从网上获取图像时,它们看起来仍然像素化。我需要将图像的比例设置为视网膜显示 (2.0),但我一定遗漏了一些东西。
这是我到目前为止所做的。
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:@"http://www.msdomains.com/tmp/test.png"];
CGRect labelFrame = CGRectMake(0,0,64,64);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:labelFrame];
imageView.contentScaleFactor = [UIScreen mainScreen].scale;
[imageView setImage:img];
[self addSubview:imageView];
[imageView release];
最佳答案
尝试在 URL 末尾添加 #@2x.png
。这不会更改 URL,但图像将被识别为视网膜 @2x 图像。它对我有用,但我将此方法与 SDWebImage 一起使用.
例如使用 http://www.msdomains.com/tmp/test.png#@2x.png
。
关于objective-c - Retina 显示来自 URL 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11491698/