Android 倒影实现算法
2010-12-18 08:03:58 来源:WEB开发网public class MirrorView extends View {
Paint m_paint;
int m_nShadowH;
Drawable m_dw;
Bitmap m_bitmap;
//xxxx
Matrix mMatrix;
int shadowHeight;
public MirrorView(Context context, Bitmap bitmap) {
super(context);
m_bitmap = bitmap;
_Init();
// TODO Auto-generated constructor stub
}
private void _Init() {
//m_dw = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
m_dw = new BitmapDrawable(m_bitmap);
m_dw.setBounds(0,0,m_dw.getIntrinsicWidth(),m_dw.getIntrinsicHeight());
m_nShadowH = m_dw.getIntrinsicHeight()/1;
m_paint = new Paint(Paint.ANTI_ALIAS_FLAG);
LinearGradient lg = new LinearGradient(0, 0, 0, m_nShadowH, 0xB0FFFFFF, 0x00000000, Shader.TileMode.CLAMP);
m_paint.setShader(lg);
m_paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
//xxxx
mMatrix = new Matrix();
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
int nX = 0;
int nY = 0;
_DrawNormalImg(canvas, nX, nY);
_DrawMirror(canvas, nX, nY);
}
private void _DrawNormalImg(Canvas canvas, int nX, int nY) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.translate(nX, nY);
m_dw.draw(canvas);
canvas.restore();
}
private void _DrawMirror(Canvas canvas, int nX, int nY) {
int nW = m_dw.getIntrinsicWidth();
int nH = m_dw.getIntrinsicHeight();
// U.dout("nW="+nW+",nH="+nH);
//xxxx
shadowHeight=nH/2;
//xxxx
float[] src={0, nH, nW, nH, nW,nH - m_nShadowH, 0, nH - m_nShadowH};
float[] dst={ 0, nH, nW, nH,nW, shadowHeight, 0, shadowHeight };
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
更多精彩
赞助商链接