2012.10.08 安卓游戏开发笔记(十二)_Bitmaps的位图渲染于操作

来源:互联网 发布:腾讯视频 for mac 编辑:程序博客网 时间:2024/06/05 06:30

Bitmaps:

1) 位图的获取:采用位图工厂

Bitmap bit = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher);

2) 位图的绘制:canvas.drawBitmap();函数绘制位图

3) 位图的旋转,分为两种: 1> 使用save()和restore()旋转画布实现 

canvas.save();canvas.rotate(30, bit.getWidth()/2, bit.getHeight()/2);canvas.drawBitmap(bit, 0, 0, paint);canvas.restore();canvas.drawBitmap(bit, 100, 0, paint);
    2>使用Matrix矩阵实现

Matrix matrix = new Matrix();matrix.postRotate(30, bit.getWidth(), bit.getHeight());canvas.drawBitmap(bit, matrix, paint);
4) 位图的平移1> canvas.translate(); new Matrix().posttranslate();

5) 位图的缩放1>canvas.scale(floate x,float y,float px,float py),前两个分别对画布x,y的缩放比例,后两个为缩放的坐标 ;2>new Matrix().postscale();(先使用translate)同上

6) 位图的镜像 只是把scale中参数作为修改第一个参数-1为x轴的镜像,第二个参数-1为y轴方向的镜像;

原创粉丝点击