041003_Matrix Android安卓开发课件.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Matrix 使用Bitmap可以进行图形的绘制,但是如果希望图形可以进行一些平移、旋转、缩放、倾斜等变换的话,则需要android.graphics.Matrix类(距阵)的支持 Matrix类操作流程 用于设置Matrix矩阵的公式 简化的Matrix矩阵的公式 范例:为60度时的矩阵 范例:设置矩阵 范例:使用Matrix进行图形的改变 范例:在布局管理器中定义组件 —— main.xml 范例:修改MyView程序,通过Matrix类提供的方法进行图片的操作 E-MAIL:mldnqa@163.com ? MLDN 软件教学研发部 Android开发实战经典 第10章:多媒体技术 —— Matrix 李兴华 北京魔乐科技软件学院 本章目标 可以使用Maxtrix实现图片的转换。 public class MyView extends View { // 继承View private Bitmap bitmap = null ; private Matrix matrix = new Matrix(); public MyView(Context context, AttributeSet attrs) { super(context, attrs); this.bitmap = BitmapFactory.decodeResource(super.getResources(), R.drawable.android_mldn); // 取得Bitmap float cosValue = (float) Math.cos(-Math.PI/3); // 60度 float sinValue = (float) Math.sin(-Math.PI/3); // 60度 this.matrix.setValues(new float[] { cosValue, // X轴的缩放,1表示原始大小 -sinValue, // 旋转的X轴 100, // x轴平移 sinValue, // 旋转Y轴 cosValue, // Y轴的缩放,1表示原始大小 200, // y轴平移 0, 0, // 视角转换 2 }); // 缩放比例,1不变,2表示1/2 } @Override protected void onDraw(Canvas canvas) { // 绘图 canvas.drawBitmap(this.bitmap, this.matrix, null); // 画图 } } ?xml version=1.0 encoding=utf-8? LinearLayout ? 线性布局管理器 xmlns:android=/apk/res/android android:orientation=vertical ? 所有组件垂直摆放 android:layout_width=fill_parent ? 布局管理器宽度为屏幕宽度 android:layout_height=fill_parent ? 布局管理器高度为屏幕高度 org.lxh.demo.MyView ? 定义组件 android:layout_width=fill_parent ? 组件宽度为屏幕宽度 android:layout_height=wrap_content / ? 组件高度为显示高度 /LinearLayout package org.lxh.demo; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.util.AttributeSet; import android.view.View; public class MyView extends View { // 继承View private Bitmap bitmap = null ; private Matrix matrix = new Matrix(); public MyView(Context context, AttributeSet attrs) { super(context, attrs); this.bitmap = BitmapFacto

文档评论(0)

autohhh + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档