自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android游戲開發(fā)之十六:實(shí)現(xiàn)圖像漸變特效

移動(dòng)開發(fā) Android 游戲開發(fā)
Android游戲中我們可以見(jiàn)到很多特效,其中就包括圖像特效處理。本文就講講在Android系統(tǒng)中如何實(shí)現(xiàn)圖像漸變特效。

在android.graphics中提供了有關(guān)Gradient字樣的類,例如LinearGradient線性漸變、 RadialGradient徑向漸變和SweepGradient角度漸變?nèi)N,他們的基類為android.graphics.Shader。為了演 示圖像漸變效果,下面給出一個(gè)簡(jiǎn)單的實(shí)例。

一、LinearGradient線性漸變

在android平臺(tái)中提供了兩種重載方式來(lái)實(shí)例化該類分別為,他們的不同之處為參數(shù)中***種方法可以用顏色數(shù)組,和位置來(lái)實(shí)現(xiàn)更細(xì)膩的過(guò)渡效果,比如顏 色采樣int[] colors數(shù)組中存放20種顏色,則漸變將會(huì)逐一處理。而第二種方法參數(shù)僅為起初顏色color0和最終顏色color1。

LinearGradient(float x0, float y0, float x1, float y1, int[] colors, float[] positions, Shader.TileMode tile) 

LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1, Shader.TileMode tile)

使用實(shí)例如下:

  1. Paint p=new Paint();    
  2. LinearGradient lg=new LinearGradient(0,0,100,100,Color.RED,Color.BLUE,Shader.TileMode.MIRROR);  //參數(shù)一為漸變起初點(diǎn)坐標(biāo)x位置,參數(shù)二為y軸位置,參數(shù)三和四分辨對(duì)應(yīng)漸變終點(diǎn),***參數(shù)為平鋪方式,這里設(shè)置為鏡像 

剛才已經(jīng)講到Gradient是基于Shader類,所以我們通過(guò)Paint的setShader方法來(lái)設(shè)置這個(gè)漸變,代碼如下:

  1. p.setShader(lg);    
  2. canvas.drawCicle(0,0,200,p); //參數(shù)3為畫圓的半徑,類型為float型。 

二、RadialGradient鏡像漸變

有了上面的基礎(chǔ),我們一起來(lái)了解下徑向漸變。和上面參數(shù)唯一不同的是,徑向漸變第三個(gè)參數(shù)是半徑,其他的和線性漸變相同。

RadialGradient(float x, float y, float radius, int[] colors, float[] positions, Shader.TileMode tile) 

RadialGradient(float x, float y, float radius, int color0, int color1, Shader.TileMode tile)

三、SweepGradient角度漸變

對(duì)于一些3D立體效果的漸變可以嘗試用角度漸變來(lái)完成一個(gè)圓錐形,相對(duì)來(lái)說(shuō)比上面更簡(jiǎn)單,前兩個(gè)參數(shù)為中心點(diǎn),然后通過(guò)載入的顏色來(lái)平均的漸變渲染。

SweepGradient(float cx, float cy, int[] colors, float[] positions)  //對(duì)于***一個(gè)參數(shù)SDK上的描述為May be NULL. The relative position of each corresponding color in the colors array, beginning with 0 and ending with 1.0. If the values are not monotonic, the drawing may produce unexpected results. If positions is NULL, then the colors are automatically spaced evenly.,所以建議使用下面的重載方法,本方法一般為NULL即可。

SweepGradient(float cx, float cy, int color0, int color1)

到此,希望大家對(duì)圖像特效處理有了一定的認(rèn)識(shí),了解這些對(duì)打好Android游戲開發(fā)的基礎(chǔ)很有好處。

責(zé)任編輯:閆佳明 來(lái)源: jizhuomi
相關(guān)推薦

2013-04-22 13:57:15

Android圖像特效

2013-05-21 13:33:02

Android游戲開發(fā)異步音樂(lè)播放

2024-01-16 08:22:42

Gradient線性梯度

2013-01-04 16:17:33

Android開發(fā)圖像特效圖像處理

2011-04-25 14:45:38

2013-05-21 11:26:49

Android游戲開發(fā)Sensor感應(yīng)

2015-09-22 10:49:40

Android滑動(dòng)漸變

2022-12-19 16:56:48

游戲開發(fā)鴻蒙

2013-05-20 17:48:20

2013-05-21 09:56:15

2013-05-21 10:42:48

Android游戲開發(fā)Bitmap位圖旋轉(zhuǎn)

2013-05-21 11:24:07

Android游戲開發(fā)Sensor重力感應(yīng)

2011-03-02 13:15:26

HTML 5jQuery

2023-02-24 08:32:50

CSS漸變屬性

2013-05-21 14:22:29

Android游戲開發(fā)捕獲屏幕雙擊事件

2013-05-20 17:33:44

Android游戲開發(fā)自定義View

2013-05-20 17:51:47

Android游戲開發(fā)SurfaceView

2013-05-21 14:15:23

Android游戲開發(fā)屏幕分辨率

2013-05-21 14:10:11

Android游戲開發(fā)SoundPool類同時(shí)多音效

2013-05-21 11:33:11

Android游戲開發(fā)按鍵中斷事件
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)