您好,登錄后才能下訂單哦!
如何進(jìn)行Android開發(fā)中引路蜂二維圖形庫(kù)的使用分析,相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
AndroidGraphics2DTutorial定義了應(yīng)用的主Activity,下面就可以開始寫每個(gè)具體的二維繪圖示例。不同的例子將盡量采用不同的UI控件:Menu,Content Menu,Dialog,Custom Dialog,Button等等。例子采用了引路蜂二維圖形庫(kù),引路蜂二維圖形庫(kù)Graphics 2D API實(shí)現(xiàn)了移動(dòng)平臺(tái)(Java ME,Blackberry,iPhone,Android,Windows Phone)上圖形引擎,它能夠以一種統(tǒng)一的方式處理各種基本圖形(Shape),路徑(Path),文本(Texts),適量字體及圖像。 簡(jiǎn)單的說來,Graphics 2D API實(shí)現(xiàn)了與之對(duì)應(yīng)的Java SE上類似的二維圖形庫(kù)API。
主要功能如下:
支持各種基本圖形:曲線,矩形,橢圓等;支持繪制任意幾何圖形
支持在圖形,文體,圖象上的碰撞檢測(cè)
增強(qiáng)的顏色扶持及顏色管理
控制圖形繪制的質(zhì)量
填充,外框,各種線條繪制
二維圖形變換
矢量字體
從左到右,從右到左,從上到下顯示文體
反走樣
透明度支持
圖標(biāo),及圖象繪制
我們?cè)贏ndroid簡(jiǎn)明開發(fā)教程九:創(chuàng)建應(yīng)用程序框架 中定義了一個(gè)基類Graphics2DActivity作為所有示例Activity的父類:
public abstract class Graphics2DActivity extends Activity{ protected Graphics2D graphics2D =SharedGraphics2DInstance.graphics2d; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } protected abstract void drawImage(); public void onStart() { super.onStart(); drawImage(); } }
其中g(shù)raphics2D為圖形畫板對(duì)象(Canvas)是以width x height 的二維整型數(shù)組來表示的。這個(gè)數(shù)組的每個(gè)值為一個(gè)32為整數(shù)。格式為ARGB,分別代表透明度,紅色,綠色,藍(lán)色。在畫板上的繪制操作(點(diǎn),線,多邊形, 填充等)是修改這些顏色值。
R.layout.main 中可以使用GuidebeeGraphics2DSurfaceView 或是GuidebeeGraphics2DView 來作為畫板的顯示結(jié)果。
抽象方法protected abstract void drawImage();用來繪制不同的內(nèi)容。
修改com.pstreets.graphics2d.example.Colors 來使用引路蜂二維圖形庫(kù)繪制不同的顏色,如果以前用過Java SE或是.Net Framework,你會(huì)覺得引路蜂二維圖形庫(kù)提供的API和它們非常相似,代碼很好理解。
public class Colors extends Graphics2DActivity{ protected void drawImage(){ /** * The solid (full opaque) red color in the ARGB space */ Color redColor = new Color(0xffff0000); /** * The semi-opaque green color in the ARGB space (alpha is 0x78) */ Color greenColor = new Color(0x7800ff00,true); /** * The semi-opaque blue color in the ARGB space (alpha is 0x78) */ Color blueColor = new Color(0x780000ff,true); /** * The semi-opaque yellow color in the ARGB space ( alpha is 0x78) */ Color yellowColor = new Color(0x78ffff00,true); /** * The dash array */ int dashArray[] = { 20 ,8 }; graphics2D.clear(Color.WHITE); SolidBrush brush=new SolidBrush(redColor); graphics2D.fillOval(brush,30,60,80,80); brush=new SolidBrush(greenColor); graphics2D.fillOval(brush,60,30,80,80); Pen pen=new Pen(yellowColor,10,Pen.CAP_BUTT,Pen.JOIN_MITER,dashArray,0); brush=new SolidBrush(blueColor); graphics2D.setPenAndBrush(pen,brush); graphics2D.fillOval(null,90,60,80,80); graphics2D.drawOval(null,90,60,80,80); } }
Colors Activity非常簡(jiǎn)單,除View之外,沒有其它UI。 按“Back”后可以退回示例列表顯示UI。
看完上述內(nèi)容,你們掌握如何進(jìn)行Android開發(fā)中引路蜂二維圖形庫(kù)的使用分析的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。