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. Java自学-集合框架 ArrayList和LinkedList的区别

    ArrayList和LinkedList的区别 步骤 1 : ArrayList和LinkedList的区别 ArrayList ,插入,删除数据慢 LinkedList, 插入,删除数据快 Arra ...

  2. python - 关于json和pickle两个序列化模块的区别

    传送门 https://stackoverflow.com/a/20980488/5955399 区别 json:用于字符串(unicode text)和python基本数据类型间进行转换.优点:跨语 ...

  3. Cosmetic Sprayer Structure Anatomy

    What shape of spray is sprayed by the cosmetic spray pump head?     Plastic Sprayers Manufacturer   ...

  4. JS获取CHECKBOX的值 AND 两个CHECKBOX 循环选中

    获取多选按钮的值 var chk_value = ''; $('input[data-action="checkRole"]:checked').each(function(){ ...

  5. @implementer,抽象类,接口

    @implementer,抽象类,接口 1.      implementer 在看twisted源码时,经常出现@implementer(IReactorFDSet) 它来自zope.interfa ...

  6. 【转载】CentOS和Ubuntu的区别

    CentOS(Community ENTerprise Operating System)是Linux发行版之一,它是来自于Red Hat Enterprise Linux依照开放源代码规定释出的源代 ...

  7. Codeforces Round #586 (Div. 1 + Div. 2)D(二分图构建,思维,结论需数论证明)

    #include<bits/stdc++.h>using namespace std;long long a[200007];vector<int>v[77];int main ...

  8. 利用Session实现三天免登陆

    什么是Session Session:在计算机中,尤其是在网络应用中,称为“会话控制”.(百度百科) Session:服务器端的数据存储技术. Session要解决什么问题 一个用户的不同请求(重定位 ...

  9. 「BOI2007」Mokia

    「BOI2007」Mokia 传送门 把查询拆成四部分然后容斥计算答案(二维前缀和) 然后 \(\text{CDQ}\) 分治算答案. 参考代码: #include <algorithm> ...

  10. CSS - 布局流程

    一.为了提高网页制作的效率,布局时通常需要遵守一定的布局流程,具体如下: "版心"(可视区) 是指网页中主体内容所在的区域.一般在浏览器窗口中水平居中显示,常见的宽度值为960px ...