当前位置:操作系统 > 安卓/Android >>

android图像绘制(二)——放缩问题

android中图像在画布上放大缩小时,图像的边框大小没有改变!

原图如下:

\

 

放大后:原来图片的边框没有改变,位置依旧!

 

\

 

所以如果要放置图片的位置的话,就需要做相应的位置移动才可以!

 


采用如下代码(全屏放置图片):

[java]
Matrix matrix = new Matrix(); 
        matrix.postScale(canvas.getWidth()*1.01f/bmpBg.getWidth(), canvas.getHeight()*1.01f/bmpBg.getHeight(), bmpBg.getWidth() / 2, bmpBg.getHeight() / 2); 
        matrix.postTranslate( (canvas.getWidth()-bmpBg.getWidth()) / 2, (canvas.getHeight()-bmpBg.getHeight()) / 2); 
        canvas.drawBitmap(bmpBg, matrix, paint); 
Matrix matrix = new Matrix();
  matrix.postScale(canvas.getWidth()*1.01f/bmpBg.getWidth(), canvas.getHeight()*1.01f/bmpBg.getHeight(), bmpBg.getWidth() / 2, bmpBg.getHeight() / 2);
  matrix.postTranslate( (canvas.getWidth()-bmpBg.getWidth()) / 2, (canvas.getHeight()-bmpBg.getHeight()) / 2);
  canvas.drawBitmap(bmpBg, matrix, paint);


 摘自 阿凯的专栏


 

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,