我正在尝试从 URL 获取图像以在 iPhone 和 iPhone Retina 上查看它。问题是 iPhone 显示正确但 Retina 模糊。图像尺寸为 100x100,分辨率为 326dpi(视网膜尺寸)。
我做得对吗?
- (void)viewDidLoad
{
[super viewDidLoad];
double scaleFactor = [UIScreen mainScreen].scale;
NSURL *imageURL = [NSURL URLWithString:@"http://s419999211.mialojamiento.es/img/bola.png"];
if (scaleFactor == 2){
// @2x
NSLog(@"Estoy cargando la imágen retina");
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
image = [UIImage imageWithData:imageData];
NSLog(@"Width: %f Height: %f",image.size.width,image.size.height);
yourImageView = [[UIImageView alloc] initWithImage:image];
} else {
// @1x
NSLog(@"Estoy cargando la imágen normal");
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
image = [UIImage imageWithData:imageData];
imagenScalada = [UIImage imageWithCGImage:[image CGImage] scale:1.0 orientation:UIImageOrientationUp];
NSLog(@"Width: %f Height: %f",imagenScalada.size.width,imagenScalada.size.height);
yourImageView = [[UIImageView alloc] initWithImage:imagenScalada];
}
[self.view addSubview:yourImageView];
}
谢谢!
iPhone 普通 iPhone 视网膜