Downloading normal image Vs retina device image (2x)

前端 未结 2 1208
终归单人心
终归单人心 2021-01-31 09:59

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 ha

相关标签:
2条回答
  • 2021-01-31 10:12

    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;
    
    0 讨论(0)
  • 2021-01-31 10:23
    CGFloat screenScale = [UIScreen mainScreen].
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:myUrl] scale:screenScale];
    
    0 讨论(0)
提交回复
热议问题