首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

旋转图片的几种形式

2012-08-21 
旋转图片的几种方式一、每次根据旋转矩阵从原位图创建出旋转后的新位图。但是缺点就是要船舰新的位图。// cre

旋转图片的几种方式
一、每次根据旋转矩阵从原位图创建出旋转后的新位图。但是缺点就是要船舰新的位图。
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// rotate the Bitmap
matrix.postRotate(45);

// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);

// make a Drawable from Bitmap to allow to set the BitMap
// to the ImageView, ImageButton or what ever
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

二、将旋转图片转为旋转画布。效率较高。Android官方Demo:LunarLander正是旋转画布,从而达到旋转图片,但是从效果上看,有些失真。(旋转图片时,一般旋转中心为图片的中心。)
(旋转方向为顺时针,若角度为负则为逆时针)

//注意画布的状态保存和恢复
canvas.save();
//参数分别为:旋转角度,图片X中心,图片Y中心。
canvas.rotate(angle, getCenterX(),getCenterY());
spriteImage.setBounds(bounds);
spriteImage.draw(canvas);
canvas.restore(); 1 楼 pop0068 2011-02-03   采用第一种方式旋转,图片会产生“微小的位置变化”,不知楼主是否有此问题? 2 楼 a526001650a 2012-05-04   这人发贴只发一点,典型的不懂装懂,直接复制别处的东西当成是自己的。

热点排行