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

首頁(yè) > 系統(tǒng) > Android > 正文

android 放大鏡ShapeDrawable妙用分享

2020-04-11 12:15:48
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

首先,ShapeDrawable構(gòu)造的時(shí)候可以指定描畫的形狀,

其次,可以通過(guò)shape.getPaint().setShader();指定Shader,shader可以接受一個(gè)圖片和matrix

所以問(wèn)題就順利的解決了:)

具體實(shí)現(xiàn)如下:
[java]

復(fù)制代碼 代碼如下:

float scale = 1.2f;

int cx = 224;
int cy = 357;
int r = 200;

// 指定形狀創(chuàng)建一個(gè)ShapeDrawable 
ShapeDrawable shape=new ShapeDrawable(new OvalShape());
Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.bg1);
BitmapShader bs = new BitmapShader(bm, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

Matrix m = new Matrix();
m.setTranslate(r-cx, r-cy);
m.postScale(scale, scale);
bs.setLocalMatrix(m);   // 圖形變換可以在這里實(shí)現(xiàn),包括區(qū)域指定 

// 為ShapeDrawable設(shè)置Shader 
shape.getPaint().setShader(bs);

// 指定描畫目標(biāo)位置 
shape.setBounds((int)(cx-r*scale),(int)(cy-r*scale),(int)(cx+r*scale),(int)(cy+r*scale));
canvas.drawBitmap(bm, 0, 0, null);
shape.draw(canvas);

float scale = 1.2f;

int cx = 224;
int cy = 357;
int r = 200;


// 指定形狀創(chuàng)建一個(gè)ShapeDrawable
ShapeDrawable shape=new ShapeDrawable(new OvalShape());
Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.bg1);
BitmapShader bs = new BitmapShader(bm, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

Matrix m = new Matrix();
m.setTranslate(r-cx, r-cy);
m.postScale(scale, scale);
bs.setLocalMatrix(m); // 圖形變換可以在這里實(shí)現(xiàn),包括區(qū)域指定

// 為ShapeDrawable設(shè)置Shader
shape.getPaint().setShader(bs);

// 指定描畫目標(biāo)位置
shape.setBounds((int)(cx-r*scale),(int)(cy-r*scale),(int)(cx+r*scale),(int)(cy+r*scale));
canvas.drawBitmap(bm, 0, 0, null);
shape.draw(canvas);

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 长垣县| 宁远县| 松江区| 德州市| 上杭县| 徐汇区| 古田县| 遵义县| 闽侯县| 搜索| 恭城| 密云县| 仲巴县| 抚顺市| 商都县| 宣汉县| 浦东新区| 察雅县| 青浦区| 乳山市| 陆川县| 阿鲁科尔沁旗| 双牌县| 曲水县| 东乌| 青河县| 板桥市| 格尔木市| 缙云县| 印江| 夏津县| 石家庄市| 井研县| 长春市| 浦江县| 织金县| 克什克腾旗| 吉水县| 太康县| 福州市| 伊吾县|