下载正常图像vs视网膜设备图像(2x) [英] Downloading normal image Vs retina device image (2x)

查看:160
本文介绍了下载正常图像vs视网膜设备图像(2x)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们需要从某个网址下载图片,并在两种设备上显示图片 - Retina(2x图片)和常规设备 - 我们是否应该使用两个不同的图片网址来处理这个?



对于资源包中的图像,我们保留了xyz.png和xyz@2x.png,并且工作正常。



对于我们从服务器获取的图像,我们需要为这些图像分别创建图像URL,并使用相同的命名约定(xyz.png和xyz@2x.png)在本地缓存它们?



请在这里扔一些光。

解决方案

您可以检查设备是否有高分辨率的视网膜显示和基于下载不同的图像。不要打扰照片和东西,你仍然会缩放界面大小。

您可以使用

  UIImage * image = //下载来创建已下载图片的缩放版本。 .. 
image = [UIImage imageWithCGImage:[image CGImage] scale:2.0 orientation:UIImageOrientationUp];

请注意,缩放的100x100图片将成为50x50磅的图片/ p>

首先检查是否有视网膜显示

  BOOL retina = NO ; 
if([[UIScreen mainScreen] respondingToSelector:@selector(scale)])
retina = [[UIScreen mainScreen] scale] == 2.0? YES:NO;


When we need to download an image from some URL and show it on two kinds of devices -- Retina (with 2x image) and regular device -- Should we have two different image URLs to handle this?

For the images in the resource bundle we are keeping both xyz.png and xyz@2x.png and its working fine.

For images we are fetching from server do we need to have separate image URLs for both these kind of images and cache them locally with the same naming convention (xyz.png and xyz@2x.png)?

Please throw some light here.

解决方案

You can check if the device has a high-resolution retina display and based on that download a different image. Don't bother for photos and stuff that you'd scale anyway for interface size.
You can create the scaled version of the downloaded image with

UIImage *image = //download...
image=[UIImage imageWithCGImage:[image CGImage] scale:2.0 orientation:UIImageOrientationUp];

Keep in mind that a scaled 100x100 image will become a 50x50 points image (with 2.0 scale).

Check first if you have a retina display

BOOL retina = NO;
if([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
    retina = [[UIScreen mainScreen] scale] == 2.0 ? YES : NO;

这篇关于下载正常图像vs视网膜设备图像(2x)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆