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(); } }

效果图:

 

图形与动画在Android中的实现的更多相关文章

  1. 在Android中显示GIF动画

    gif图动画在android中还是比较常用的,比如像新浪微博中,有很多gif图片,而且展示非常好,所以我也想弄一个.经过我多方的搜索资料和整理,终于弄出来了,其实github上有很多开源的gif的展示 ...

  2. 【转】[置顶] 在Android中显示GIF动画

    gif图动画在Android中还是比较常用的,比如像新浪微博中,有很多gif图片,而且展示非常好,所以我也想弄一个.经过我多方的搜索资料和整理,终于弄出来了,其实github上有很多开源的gif的展示 ...

  3. Android中的动画具体解释系列【2】——飞舞的蝴蝶

    这一篇来使用逐帧动画和补间动画来实现一个小样例,首先我们来看看Android中的补间动画. Android中使用Animation代表抽象的动画类,该类包含以下几个子类: AlphaAnimation ...

  4. Android中的动画详解系列【2】——飞舞的蝴蝶

    这一篇来使用逐帧动画和补间动画来实现一个小例子,首先我们来看看Android中的补间动画. Android中使用Animation代表抽象的动画类,该类包括下面几个子类: AlphaAnimation ...

  5. Android中矢量动画

    Android中矢量动画 Android中用<path> 标签来创建SVG,就好比控制着一支画笔,从一点到一点,动一条线. <path> 标签 支持一下属性 M = (Mx, ...

  6. 初识android中的动画

    动画效果可以大大提高界面的交互效果,因此,动画在移动开发中的应用场景较为普遍.掌握基本的动画效果在成熟的软件开发中不可或缺.除此之外,用户对于动画的接受程度远高于文字和图片,利用动画效果可以加深用户对 ...

  7. Android中的Drawable和动画

    Android中Drawable是一种可以在Canvas上进行绘制抽象的概念,种类很多,常见的颜色和图片都可以是一个Drawable.Drawable有很多种,它们表示一种图像的概念,但是它们又不全是 ...

  8. 【Android】第21章 2D图形和动画

    分类:C#.Android.VS2015: 创建日期:2016-03-19 一.简介 Android系统定义了一系列独立的图形处理类,其中,2D图形处理类分别位于以下命名空间: Android.Gra ...

  9. Android中自定义View和自定义动画

    Android FrameWork 层给我们提供了很多界面组件,但是在实际的商业开发中这些组件往往并不能完全满足我们的需求,这时候我们就需要自定义我们自己的视图和动画. 我们要重写系统的View就必须 ...

随机推荐

  1. php面试题之PHP核心技术

    一.PHP核心技术 更多PHP相关知识请关注我的专栏PHP​zhuanlan.zhihu.com 1.写出一个能创建多级目录的PHP函数(新浪网技术部) <?php /** * 创建多级目录 * ...

  2. Python经典排序算法

    https://www.cnblogs.com/onepixel/p/7674659.html这个文章很nice https://www.bilibili.com/video/av685670?fro ...

  3. spark实验(一)--linux系统常见命令及其文件互传(2)

    2.使用 Linux 系统的常用命令 启动 Linux 虚拟机,进入 Linux 系统,通过查阅相关 Linux 书籍和网络资料,或者参考 本教程官网的“实验指南”的“Linux 系统常用命令”,完成 ...

  4. Scrapy 分布式爬取

    由于受到计算机能力和网络带宽的限制,单台计算机运行的爬虫咋爬取数据量较大时,需要耗费很长时间.分布式爬取的思想是“人多力量大”,在网络中的多台计算机同时运行程序,公童完成一个大型爬取任务, Scrap ...

  5. 时间和日期实例-<Calender计算出生日期相差几天>

    String day1="1994:10:04"; String day2="1994:10:03"; SimpleDateFormat format= new ...

  6. 使用jquery select2实现下拉框搜索功能

    由于公司后台系统下拉框数据量太多了,用户操作起来要不方便所以增加了下拉框里面一个搜索功能 1从官网下载jquery select2 下来 地址https://select2.github.io/ 2: ...

  7. Controller层注解

    /** * Copyright © 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite< ...

  8. 第一个Vue-cli创建项目

    需要环境: Node.js:http://nodejs.cn/download/ 安装完成之后,使用cmd测试: 我现在的是最新的 安装Node.js加速器: 这个下载的稍微慢一些 npm insta ...

  9. Django 学习之中间件Middleware

    一.中间件介绍 中间件顾名思义,是介于request与response处理之间的一道处理过程,相对比较轻量级,并且在全局上改变django的输入与输出.因为改变的是全局,所以需要谨慎实用,用不好会影响 ...

  10. Java8 HashMap详解

    Java8 HashMap Java8 对 HashMap 进行了一些修改,最大的不同就是利用了红黑树,所以其由 数组+链表+红黑树 组成. 根据 Java7 HashMap 的介绍,我们知道,查找的 ...