国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS像素對齊概念解析

2019-10-21 18:52:22
字體:
來源:轉載
供稿:網友

在iOS中,有一個概念叫做像素對齊,如果像素不對齊,那么在GPU渲染時,需要進行插值計算,這個插值計算的過程會有性能損耗。 

在模擬器上,有一個選項可以把像素不對齊的部分顯示出來。

iOS,像素,對齊

邏輯像素與物理像素

在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。

iOS,像素,對齊

部分代碼

  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];

 結論
 1.所謂的像素對齊,指的是物理像素對齊。
 2.如果是2x的圖像,放在3x的屏幕上(6sp),也會發生像素不對齊的情況。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 民权县| 昌宁县| 峨山| 定结县| 宁陵县| 江川县| 拉孜县| 宜阳县| 镇原县| 弥勒县| 九江县| 罗山县| 呼伦贝尔市| 衢州市| 乌苏市| 伊宁市| 瓦房店市| 酒泉市| 海林市| 宁强县| 阿鲁科尔沁旗| 东乌珠穆沁旗| 从化市| 米脂县| 连州市| 易门县| 郸城县| 祁阳县| 启东市| 建水县| 灯塔市| 西昌市| 长垣县| 永清县| 秦安县| 兴城市| 屏东市| 灵石县| 铅山县| 伊宁市| 资中县|