简体   繁体   English

UIImage中加载的图像在视网膜上像素化

[英]Loaded image in UIImage is pixelated on retina

I parsed the data from a web which also contains jpg image. 我从包含jpg图像的网络中解析数据。 The problem is that the image looks blurry/pixelated on retina display. 问题是图像在视网膜显示器上看起来模糊/像素化。 Any solution for this? 对此有何解决方案? Thanks. 谢谢。

NSData *data = [NSData dataWithContentsOfURL:linkUrl];
            UIImage *img = [[UIImage alloc] initWithData:data];   

          //  detailViewController.faces.contentScaleFactor=[UIScreen mainScreen].scale;//Attampt to solve the problem

            detailViewController.faces.image=img;

After initializing your image with the data, create a new one from it with the correct scale like this: 使用数据初始化图像后,使用正确的比例从中创建一个新的图像,如下所示:

img = [UIImage imageWithCGImage:img.CGImage scale:[UIScreen mainScreen].scale orientation:img.imageOrientation];

...but note that the image will now appear half the size on retina displays unless you scale it up, for example by stretching it in an image view. ...但请注意,除非您将其放大,例如在图像视图中拉伸,否则图像现在将显示在视网膜显示屏上的一半大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM