android:动态设置ImageView,Bitmap的长宽
在代码中设置ImageView图片的大小的方法:
imageView.setImageResource(R.drawable.newscar);
LayoutParams params = imageView.getLayoutParams();
params.height=200;
params.width =100;
imageView.setLayoutParams(params);
在代码中设置Bitmap图片的大小的方法以:
public 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);
// 得到新的图片
www.2cto.com
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
return newbm;
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);
// 得到新的图片
www.2cto.com
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
return newbm;
}
版权声明:本文为liu943367080原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。