在一个项目中用到了全屏显示bitmap,由前面的从图库或是直接拍照获得的图片是经过压缩的,这里就说一下怎么调整bitmap的样式大小

 public static Bitmap resizeImage(Bitmap originalBitmap) {
int width = originalBitmap.getWidth();
int height = originalBitmap.getHeight();
//screenWidth为手机屏幕的宽
//screenHeight为手机屏幕的高
float scanleWidth = 0;
float scanleHeight = 0;
if (width > height) {
//横屏的图片
if (width > screenWidth / 2) {
scanleWidth = (float) ((float) screenWidth / (float) width );
scanleHeight = scanleWidth;
} else {
scanleWidth = (float) screenWidth / (float) 2 / (float) width;
scanleHeight = scanleWidth;
}

}
if (width <= height) {
//竖屏的图片
if (width >= screenWidth / 2) {
scanleWidth = (float) ((float) screenWidth / (float) width);

scanleHeight = scanleWidth;
} else {
scanleWidth = (float) screenWidth / (float) 2 / (float) width;
scanleHeight = scanleWidth;
}
}


//操作图片使用的matrix对象 Matrix
Matrix matrix = new Matrix();
// 缩放图片动作

matrix.postScale(scanleWidth, scanleHeight);


//旋转图片 动作
// matrix.postRotate(45);
// 创建新的图片Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(originalBitmap, 0, 0, width, height, matrix, true);
// 用完了记得回收
// resizedBitmap.recycle();
return resizedBitmap;
}

更多相关文章

  1. Android多线程下载远程图片【转】
  2. Android界面的.9.png图片显示出错,怎么回事啊?
  3. 关于Android4.0之上的ListView显示从网络上获取图片和文字
  4. Android 图片添加水印图片或者文字
  5. 拍照后获取不了图片!
  6. Android——播放器和图片轮播
  7. Android实现非本地图片的点击效果
  8. Android自定义Toast带图片的
  9. Android 自定义控件 改变图片颜色来实现类似selector点击更改颜

随机推荐

  1. 第十一章:性能和可伸缩性——Java并发编程
  2. 在servlet中的init方法得到了对数据库操
  3. 轻量级javaEE SSH 01: 概述 环境与工具篇
  4. java时间转换,long , string和date和时间
  5. Java中PreparedStatement与Statement区别
  6. Java中的观察者模式
  7. Java连接Oracle数据库简单实例
  8. java集合框架系列-TreeMap介绍
  9. 八门神器 - GameKiller 中的防破解技术(附
  10. 看了“我们中应该有英雄”,也来愤青一下!