zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

Android -- 重置Bitmap大小&&Bitmap转角度

Androidamp -- 大小 重置 角度 bitmap
2023-09-27 14:27:47 时间

重置Bitmap大小                                                                          

复制代码
Bitmap bitMap = BitmapFactory.decodeFile(path);
int width = bitMap.getWidth();
int height = bitMap.getHeight();
// 设置想要的大小
int newWidth = 500;
int newHeight = 400;
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
 bitMap = Bitmap.createBitmap(bitMap, 0, 0, width, height, matrix, true);
复制代码

Bitmap转角度                                                                            

Bitmap bm = BitmapFactory.decodeByteArray(imgdata, 0,imgdata.length);
Matrix matrix = new Matrix();
matrix.preRotate(270);
bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),bm.getHeight(), matrix, true);

imgdata为camera开发的时候的图片数据。

这里其实找到了bitmap就OK了。