[iOS]iOS的字型大小轉換問題

來源:互聯網
上載者:User

[iOS]iOS的字型大小轉換問題

一,px和pt轉換

px:相對長度單位。像素(Pixel)。(PS字型)
pt:絕對長度單位。點(Point)。(iOS字型)
公式如下:
pt=(px/96)*72。


二,字型間轉換
1in = 2.54cm = 25.4 mm = 72pt = 6pc
具體換算是:
Points Pixels Ems Percent
6pt 8px 0.5em 50%
7pt 9px 0.55em 55%
7.5pt 10px 0.625em 62.5%
8pt 11px 0.7em 70%
9pt 12px 0.75em 75%
10pt 13px 0.8em 80%
10.5pt 14px 0.875em 87.5%
11pt 15px 0.95em 95%
12pt 16px 1em 100%
13pt 17px 1.05em 105%
13.5pt 18px 1.125em 112.5%
14pt 19px 1.2em 120%
14.5pt 20px 1.25em 125%
15pt 21px 1.3em 130%
16pt 22px 1.4em 140%
17pt 23px 1.45em 145%
18pt 24px 1.5em 150%
20pt 26px 1.6em 160%
22pt 29px 1.8em 180%
24pt 32px 2em 200%
26pt 35px 2.2em 220%
27pt 36px 2.25em 225%
28pt 37px 2.3em 230%
29pt 38px 2.35em 235%
30pt 40px 2.45em 245%
32pt 42px 2.55em 255%
34pt 45px 2.75em 275%
36pt 48px 3em 300%

3、像素與毫米的轉換
轉換還需要知道另一個參數:DPI(每英寸多少點)
象素數 / DPI = 英寸數
英寸數 * 25.4 = 毫米數
對於顯示裝置,不管是印表機還是螢幕,都有一種通用的方法
先用GetDeviceCaps(裝置控制代碼,LOGPIXELSX)
或者
GetDeviceCaps(裝置控制代碼,LOGPIXELSY)獲得裝置每英寸的像素數
分別記為:px 和 py
一英寸等於25.4mm
那麼毫米換算成像素的公式為
水平方向的換算: x * px /25.4
垂直方向的換算: y * py /25.4
像素換算為毫米 x * 25.4 / px
在程式中這麼寫
MyControl.Height := 10{mm} * PixelsPerInch * 10 div 254;
分子和分母同乘以10,將浮點數運算轉化為整數運算,效率更高

常用的1024x768或800x600等標準的解析度計算出來的dpi是一個常數:96,因此計算出來的毫米與像素的關係也約等於一個常數:

基本上 1毫米 約等於 3.78像素

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.