欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android 放大鏡ShapeDrawable妙用分享

 更新時間:2013年06月04日 10:33:47   作者:  
android上想實現(xiàn)局部放大的效果,比如畫面中加個放大鏡的效果,發(fā)現(xiàn)ShapeDrawable是一個最好的選擇。

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

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

所以問題就順利的解決了:)

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

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

float scale = 1.2f;

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

// 指定形狀創(chuàng)建一個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);   // 圖形變換可以在這里實現(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)建一個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); // 圖形變換可以在這里實現(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);

相關(guān)文章

最新評論