歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android圖形圖像函數匯集

Android圖形圖像函數匯集

日期:2017/3/1 9:53:58   编辑:Linux編程

一、 Android.graphics.Matrix
有關圖形的變換、縮放等相關操作常用的方法有:
void reset() // 重置一個matrix對象。
void set(Matrix src) //復制一個源矩陣,和本類的構造方法 Matrix(Matrix src) 一樣
boolean isIdentity() //返回這個矩陣是否定義(已經有意義)
void setRotate(float degrees) //指定一個角度以0,0為坐標進行旋轉
void setRotate(float degrees, float px, float py)//指定一個角度以px,py為坐標進行旋轉
void setScale(float sx, float sy) // 縮放
void setScale(float sx, float sy, float px, float py) //以坐標px,py進行縮放
void setTranslate(float dx, float dy) //平移
void setSkew (float kx, float ky, float px, float py) //以坐標px,py進行傾斜
void setSkew (float kx, float ky) //傾斜

二、android.graphics.NinePatch
NinePatch是Android平台特有的一種非矢量圖形自然拉伸處理方法,可以幫助常規的圖形在拉伸時不會縮放,實例中Android開發網提示大家對於Toast的顯示就是該原理,同時SDK中提供了一個工具名為Draw 9-Patch,有關該工具的使用方法可以參考我們經發布的 Draw 9-Patch 使用方法介紹一文。由於該類提供了高質量支持透明的縮放方式,所以圖形格式為PNG,文件命名方式為.9.png 的後綴比如android123.9.png。

三、android.graphics.Paint
Paint類我們可以理解為畫筆、畫刷的屬性定義,本類常用的方法如下:
void reset() //重置
void setARGB(int a, int r, int g, int b) 或 void setColor(int color) 均為設置Paint對象的顏色
void setAntiAlias(boolean aa)//是否抗鋸齒,需要配合void setFlags(Paint.ANTI_ALIAS_FLAG)
來幫助消除鋸齒使其邊緣更平滑。
Shader setShader(Shader shader)//設置陰影,Shader類是一個矩陣對象,如果為NULL將清除陰影。
void setStyle(Paint.Style style) //設置樣式,一般為 FILL 填充,或者STROKE凹陷效果。
void setTextSize(float textSize) //設置字體大小
void setTextAlign(Paint.Align align) //文本對齊方式
Typeface setTypeface(Typeface typeface) //設置字體,通過Typeface可以加載Android內部的字體,一般為宋體對於中文,部分ROM可以自己添加比如雅黑等等
void setUnderlineText(boolean underlineText) //是否設置下劃線,需要撇和void setFlags (Paint.UNDERLINE_TEXT_FLAG) 方法。

四、android.graphics.Rect
Rect我們可以理解為矩形區域,類似的還有Point一個點,Rect類除了表示一個矩形區域位置描述外,android123 提示主要可以幫助我們計算圖形之間是否碰撞(包含)關系,對於Android游戲開發比較有用,其主要的成員contains包含了三種重載方法,來判斷包含關系
boolean contains(int left, int top, int right, int bottom)
boolean contains(int x, int y)
boolean contains(Rect r)

五、android.graphics.Region
Region在Android平台中表示一個區域和Rect不同的是,它表示的是一個不規則的樣子,可以是橢圓、多邊形等等,而Rect僅僅是矩形。同樣Region的boolean contains(int x, int y) 成員可以判斷一個點是否在該區域內

六、android.graphics.Typeface
Typeface類是幫助描述一個字體對象,在TextView中通過使用setTypeface方法來制定一個輸出文本的字體,其直接構造調用成員create方法可以直接指定一個字體名稱和樣式,比如
static Typeface create(Typeface family, int style)
static Typeface create(String familyName, int style)
同時使用isBold 和isItalic 方法可以判斷出是否包含粗體或斜體的字型。
final boolean isBold()
final boolean isItalic()
該類的創建方法還有從apk的資源或從一個具體的文件路徑,其具體方法為
static Typeface createFromAsset(AssetManager mgr, String path)
static Typeface createFromFile(File path)
static Typeface createFromFile(String path)

推薦閱讀: Android中SQLite構造函數參數Context的幾點注意事項 http://www.linuxidc.com/Linux/2013-02/79254.htm

更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11

Copyright © Linux教程網 All Rights Reserved