首页 > 移动平台 > 详细

android 图片缩放与旋转

时间:2021-07-10 11:14:04      阅读:22      评论:0      收藏:0      [点我收藏+]

一.装载图片

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();
}
?

android 图片缩放与旋转

原文:https://blog.51cto.com/u_15298588/3034034

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!