public class MyView extends View{
Bitmap myBitmap;
Paint paint;
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
this.initBitmap();
}
public void initBitmap(){
paint = new Paint();
myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.img); }
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setTextSize(15);
canvas.drawBitmap(myBitmap, 10, 10, paint); //Saves the current matrix and clip onto a private stack.
//Subsequent calls to translate,scale,rotate,skew,concat or clipRect,clipPath
//will all operate as usual, but when the balancing call to restore() is made,
//those calls will be forgotten, and the settings that existed before the save() will be reinstated(恢复).
//Returns:
//The value to pass to restoreToCount() to balance this save()
int i = canvas.save();
System.out.println("current count -- > " + i); Matrix m1 = new Matrix();
m1.setTranslate(500, 10);
Matrix m2 = new Matrix();
m2.setRotate(15);
Matrix m3 = new Matrix();
m3.setConcat(m1, m2);
m1.setScale(0.8f, 0.8f);
m2.setConcat(m3, m1);
canvas.drawBitmap(myBitmap, m2, paint); //This call balances a previous call to save(), and is used to
//remove all modifications to the matrix/clip state since the last save call.
//It is an error to call restore() more times than save() was called.
canvas.restore();
int j = canvas.save();
System.out.println("current count -- > " + j);
paint.setAlpha(180);
m1.setTranslate(200, 100);
m2.setScale(1.3f, 1.3f);
m2.setConcat(m1, m2);
canvas.drawBitmap(myBitmap, m3, paint); //Restores the paint to its default settings.
paint.reset();
canvas.restore();
paint.setTextSize(40);
paint.setColor(Color.BLUE);
canvas.drawText("图片的宽度:" + myBitmap.getWidth(), 150, 220, paint);
canvas.drawText("图片的高度:" + myBitmap.getHeight(), 150, 300, paint);
paint.reset(); } }

效果图:

 

最新文章

  1. web程序的路径笔记
  2. 设置WPF输入框焦点
  3. iOS开发——UI进阶篇(十三)UITabBarController简单使用,qq主流框架
  4. 那些年我们一起追过的Linux命令
  5. Maven打jar包
  6. V-rep学习笔记:机器人逆运动学数值解法(The Pseudo Inverse Method)
  7. myeclipse ctrl+shift+F失效
  8. Java用链表实现栈和队列
  9. Android 之 Window、WindowManager 与窗口管理
  10. 从零开始写自己的PHP框架系列教程(二)[App.php]
  11. C/C++程序中内存被非法改写的一个检测方法
  12. 递归打印lua中的table
  13. Spring的声明式事务管理<tx:advice/>
  14. HTTP 协议常见的状态码
  15. ssm知识点总结
  16. php网站速度性能优化(转)
  17. python基础初识介绍以及安装
  18. RNN文章总结
  19. python 3.x 循环读取文件用户登录
  20. Java根据两点的经纬度来计算之间的距离

热门文章

  1. 1007 Maximum Subsequence Sum (25分) 求最大连续区间和
  2. notepad++一次去掉所有空行,然后加上2个空行
  3. 解题报告:luogu P5755 [NOI2000]单词查找树
  4. nginx_1_初始nginx
  5. Xcode Edit Schemes
  6. win10安装Oracle11g
  7. redis之常见操作
  8. OOP的四大特征
  9. 2_01_MSSQL课程_查询
  10. 关于req.params、req.query、req.body等请求对象