gpt4 book ai didi

Android 倒影算法的实现代码

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 24 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章Android 倒影算法的实现代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

复制代码 代码如下

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 };   //xxxx   canvas.save();   mMatrix.setPolyToPoly(src, 0, dst, 0, src.length >> 1);   canvas.concat(mMatrix);   //draw mirror image    canvas.save(Canvas.MATRIX_SAVE_FLAG);   canvas.scale(1.0f, -1.0f);   canvas.translate(nX, -(nY + nH * 2));   canvas.clipRect(0, nH, nW, nH - m_nShadowH);   m_dw.draw(canvas);   canvas.restore();   //draw mask    canvas.save();   canvas.translate(nX, nY + nH);   canvas.drawRect(0, 0, nW, m_nShadowH, m_paint);   canvas.restore();   //xxxx   canvas.restore();  } } 。

最后此篇关于Android 倒影算法的实现代码的文章就讲到这里了,如果你想了解更多关于Android 倒影算法的实现代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com