图形与动画在Android中的实现
2024-10-08 13:23:22
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(); } }
效果图:
最新文章
- web程序的路径笔记
- 设置WPF输入框焦点
- iOS开发——UI进阶篇(十三)UITabBarController简单使用,qq主流框架
- 那些年我们一起追过的Linux命令
- Maven打jar包
- V-rep学习笔记:机器人逆运动学数值解法(The Pseudo Inverse Method)
- myeclipse ctrl+shift+F失效
- Java用链表实现栈和队列
- Android 之 Window、WindowManager 与窗口管理
- 从零开始写自己的PHP框架系列教程(二)[App.php]
- C/C++程序中内存被非法改写的一个检测方法
- 递归打印lua中的table
- Spring的声明式事务管理<;tx:advice/>;
- HTTP 协议常见的状态码
- ssm知识点总结
- php网站速度性能优化(转)
- python基础初识介绍以及安装
- RNN文章总结
- python 3.x 循环读取文件用户登录
- Java根据两点的经纬度来计算之间的距离
热门文章
- 1007 Maximum Subsequence Sum (25分) 求最大连续区间和
- notepad++一次去掉所有空行,然后加上2个空行
- 解题报告:luogu P5755 [NOI2000]单词查找树
- nginx_1_初始nginx
- Xcode Edit Schemes
- win10安装Oracle11g
- redis之常见操作
- OOP的四大特征
- 2_01_MSSQL课程_查询
- 关于req.params、req.query、req.body等请求对象