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

首頁 > 系統 > iOS > 正文

iOS像素對齊概念解析

2020-07-26 03:13:17
字體:
來源:轉載
供稿:網友

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

部分代碼

  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),也會發生像素不對齊的情況。

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 清徐县| 布尔津县| 东安县| 琼结县| 隆安县| 龙江县| 中西区| 依安县| 南城县| 宣恩县| 凌海市| 武功县| 尚义县| 上饶市| 江西省| 张家口市| 灵石县| 铜山县| 黔南| 吉木萨尔县| 阿瓦提县| 威宁| 福建省| 明光市| 昭苏县| 平乐县| 惠水县| 麟游县| 渭南市| 安塞县| 开阳县| 德阳市| 玉溪市| 延长县| 宁德市| 西宁市| 邯郸县| 安溪县| 电白县| 迭部县| 丹巴县|