iOS開發之圖片解析度與像素對齊,ios解析度像素對齊

來源:互聯網
上載者:User

iOS開發之圖片解析度與像素對齊,ios解析度像素對齊
像素對齊的概念

在iOS中,有一個概念叫做像素對齊,如果像素不對齊,那麼在GPU渲染時,需要進行插值計算,這個插值計算的過程會有效能損耗。
在模擬器上,有一個選項可以把像素不對齊的部分顯示出來。
邏輯像素與物理像素

在iOS裝置上,有point(邏輯像素)的概念,以及pixel(物理像素)的概念。
在編程式時,用的是point,實際渲染時用的是pixel。一個point可以對應多個pixel。
point和pixel的比例是可以通過[[UIScreen mainScreen] scale]來制定。

UIImage的scale概念

If you load an image from a file whose name includes the @2x modifier, the scale is set to 2.0. You can also specify an explicit scale factor when initializing an image from a Core Graphics image. All other images are assumed to have a scale factor of 1.0.

image也有size的概念。

This value reflects the logical size of the image and takes the image’s current orientation into account. Multiply the size values by the value in the scale property to get the pixel dimensions of the image.

就是說image的size和image和scale相乘,得到物理像素的大小。

問題

那麼像素不對齊指的是物理像素(pixel)和邏輯像素(point)對齊呢?

實驗

使用300*225像素的png圖片。分別使用不同的方法load到記憶體中,得到不同的size和scale,然後放在不同size的imageview裡。使用color misaligned images來判定是否像素對齊。
這裡模擬器使用的iPhone 6,螢幕的 scale是2。

image size image scale imageview Size 是否misalign
300,225 1 300,225
300,225 1 150,112.5
150,112.5 2 150,112.5
150,112.5 2 75,56.25
部分代碼
    NSLog(@"screen scale is %f",[[UIScreen mainScreen] scale]);    UIImage *image = [UIImage imageNamed:@"test.png"];    NSLog(@"image size %@, scale %f ", [NSValue valueWithCGSize:image.size], image.scale);    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];//    imageView.frame = CGRectMake(50, 100, imageView.bounds.size.width * 2/3, imageView.bounds.size.height * 2/3);    imageView.frame = CGRectMake(50, 100, imageView.bounds.size.width, imageView.bounds.size.height);    NSLog(@"imageView frame %@", [NSValue valueWithCGRect:imageView.frame]);    [self.view addSubview:imageView];
結論

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.