其他分享
首页 > 其他分享> > android 图片缩放与旋转

android 图片缩放与旋转

作者:互联网

一.装载图片

BitmapFactory.decodeFile(pathName);
二.缩放图片
Matrix matrix = new Matrix();  
matrix.reset();
float scaleWidth = ((float) 320) / bitmap.getWidth();
float scaleHeight = ((float) 240) / bitmap.getHeight();
matrix.postScale(scaleWidth, scaleHeight);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
三.旋转图片
Matrix matrix = new Matrix(); 
matrix.reset();
matrix.postRotate(180);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,true);
四.保存图片
File file = new File(path);
FileOutputStream outStream = null;
try
{
outStream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, outStream);
   outStream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
 

标签:Matrix,缩放,float,outStream,bitmap,new,android,旋转,matrix
来源: https://blog.51cto.com/u_15298588/3034034