使用矩阵设置ImageView



public class MyView extends  View {


public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
// initialize1();  
initialize();  
}


private Bitmap mBitmap;  


private Matrix mMatrix = new Matrix();  


public MyView(Context context) {  


super(context);   


}  
//第一种方式使用原生矩阵
private void initialize1() {       


mBitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.rtf)).getBitmap(); 
//角度大于零代表顺时针旋转
//cosValue,sinValue 旋转的角度的余弦值       平移距离  px,py    受scale影响
float cosValue = (float) Math.cos(Math.PI/6);   
float sinValue = (float) Math.sin(Math.PI/6); 
int  scale=2;
int px=500,py=500;
mMatrix.setValues(  
new float[]{  
cosValue, sinValue, px,  
-sinValue, cosValue, py,  
0, 0, scale});  


}   
//第二种方式使用androidAPI设置矩阵
private void initialize() {  


Bitmap bmp = ((BitmapDrawable)getResources().getDrawable(R.drawable.rtf)).getBitmap();  
mBitmap = bmp;  
//控制缩放比例
mMatrix.setScale(0.5f, 0.5f);  
//平移到(x,y)处  
mMatrix.postTranslate(500, 500);  
/**
* 图像倾斜    

* kx  控制y轴     正数逆时针倾斜
* ky  控制x轴    正数 顺时针倾斜 
* 如果kx=ky  效果与图像旋转 类似
* px py  控制位置
*/ 
mMatrix.postSkew(0.3f, 0.3f, 0,0); 
/**
* 图像旋转     
* degrees 大于零为顺时针
* px py  旋转中心坐标

*/
mMatrix.postRotate(50,500,500);
}  
@Override protected void onDraw(Canvas canvas) {  
//      super.onDraw(canvas);  //如果界面上还有其他元素需要绘制,只需要将这句话写上就行了。  


canvas.drawBitmap(mBitmap, mMatrix, null);  
}  


}


更多转载:http://blog.csdn.net/mengweiqi33/article/details/7446383

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无极宝

你的鼓励是我的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值