标签:
*文本、图片、音频、视频都属于多媒体
*图片
public void click(View v){
//解析图片时需要使用到的参数都封装在这个对象里了
Options opt = new Options();
//不为像素申请内存,只获取图片宽高
opt.inJustDecodeBounds = true;
BitmapFactory.decodeFile("sdcard/dog.jpg", opt);
//拿到图片宽高
int imageWidth = opt.outWidth;
int imageHeight = opt.outHeight;
Display dp = getWindowManager().getDefaultDisplay();
//拿到屏幕宽高
int screenWidth = dp.getWidth();
int screenHeight = dp.getHeight();
//计算缩放比例
int scale = 1;
int scaleWidth = imageWidth / screenWidth;
int scaleHeight = imageHeight / screenHeight;
if(scaleWidth >= scaleHeight && scaleWidth >= 1){
scale = scaleWidth;
}
else if(scaleWidth < scaleHeight && scaleHeight >= 1){
scale = scaleHeight;
}
//设置缩放比例
opt.inSampleSize = scale;
opt.inJustDecodeBounds = false;
Bitmap bm = BitmapFactory.decodeFile("sdcard/dog.jpg", opt);
ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setImageBitmap(bm);
}
标签:
原文地址:http://www.cnblogs.com/myzzx/p/5065256.html