Android菜鸟日记
19图片旋转
之前做图片旋转都很2的去复写类然后写一个方法去旋转。
其实完全可以把图片转成bitmap图 然后再调用bitmap的方法去旋转。
Matrix temp=new Matrix();
// Matrix 为 import android.graphics.Matrix;
temp.setRotate(90.0f);
//对matrix对象设置旋转角度
Bitmap bt=((BitmapDrawable)this.getResources().getDrawable(R.drawable.icon2)).getBitmap();
//从资源文件中获得Drawable对象强转成BitmapDrawable然后获取bitmap.
ImageView im1= (ImageView)this.findViewById(R.id.im1);
bt=bt.createBitmap(bt, 0, 0, bt.getWidth(),bt.getHeight(),temp,true);
//重绘bitmap(参数包括matrix对象)然后吧重绘后的对象重新赋值
im1.setImageBitmap(bt);
2011-9-22
poolo
19图片旋转
之前做图片旋转都很2的去复写类然后写一个方法去旋转。
其实完全可以把图片转成bitmap图 然后再调用bitmap的方法去旋转。
Matrix temp=new Matrix();
// Matrix 为 import android.graphics.Matrix;
temp.setRotate(90.0f);
//对matrix对象设置旋转角度
Bitmap bt=((BitmapDrawable)this.getResources().getDrawable(R.drawable.icon2)).getBitmap();
//从资源文件中获得Drawable对象强转成BitmapDrawable然后获取bitmap.
ImageView im1= (ImageView)this.findViewById(R.id.im1);
bt=bt.createBitmap(bt, 0, 0, bt.getWidth(),bt.getHeight(),temp,true);
//重绘bitmap(参数包括matrix对象)然后吧重绘后的对象重新赋值
im1.setImageBitmap(bt);
2011-9-22
poolo
本文介绍Android开发中高效实现图片旋转的方法,通过将图片转换为bitmap并利用Matrix对象进行旋转操作,避免了繁琐的类复写。具体步骤包括创建Matrix对象、设置旋转角度、加载资源文件中的Drawable为Bitmap,最后使用Matrix对象重绘并更新ImageView。

被折叠的 条评论
为什么被折叠?



