android 更改图片的大小,比方说原图片是1800*2400px,现在我需要给定宽度为600px,等比例缩小相当于重新生成一个图片为600*800px 如果还是不清楚的话,那么明确的说:就是相当于使用photoshop将大分辨率的图片缩小然后保存,再拿来使用。求大神帮助。Android图片bitmapimage 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看一下Android bitmap图像处理,有等比缩小的方法 public static Bitmap zoomImg(Bitmap bm, int newWidth ,int newHeight){ // 获得图片的宽高 int width = bm.getWidth(); int height = bm.getHeight(); // 计算缩放比例 float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // 取得想要缩放的matrix参数 Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); // 得到新的图片 Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); return newbm;} 用bitmap可以通过或取原来图片的宽高进行等比例缩小和放大:BitmapFactory.Options option = new BitmapFactory.Options(); option.inSampleSize = 2; //将图片设为原来宽高的1/2 Bitmap bm = BitmapFactory.decodeFile("",option);//文件流 直接使用Drawable也能达到同样的效果吧? 自问自答吧,使用这个将图片扩大或者缩小:ThumbnailUtils.extractThumbnail(source, width, height); try this : Bitmap.createScaledBitmap(bitmap,width,height); 在同一个wifi下,如何实现手机与pc的交互 大家看看我这个地图移动的效果是怎么回事?哪里的问题? Oauth 认证问题 图片效果处理 service后台播放问题 android:videoView播放的几个问题 如何根据contact id获取 联系人名称及其他信息? JS哪里不对啊 Intent页面跳转语法求纠正 新手代码问题,没用到数据库却显示数据库安全性不好 关于android qq 头像的问题。 如何自定义一个监听?
// 获得图片的宽高
int width = bm.getWidth();
int height = bm.getHeight();
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
return newbm;
}
BitmapFactory.Options option = new BitmapFactory.Options();
option.inSampleSize = 2; //将图片设为原来宽高的1/2
Bitmap bm = BitmapFactory.decodeFile("",option);//文件流
自问自答吧,使用这个将图片扩大或者缩小:
ThumbnailUtils.extractThumbnail(source, width, height);
Bitmap.createScaledBitmap(bitmap,width,height);