图片优化--缩略图

 

 

BitmapFactory . Options option = new Options();

option . inJustDecodeBounds = true ;            //只加载图片的头信息

BitmapFactory . decodeFile(url , option);

int picWidth = option . outWidth;                  //获取图片宽

int picHeight = option . outHeight               //获取图片高

 

Display  display  =  getWindowManager() . getDefaultDisplay();

int width =  display . getWidth();              //获取屏幕宽

int  height = display . getHeight();          //获取屏幕高

 

int  scaleX = picWidth / width ;               //宽的比

int  scaleY = picHeight / height;             //高的比

 

if(scaleX > scaleY && scaleY>1){

              option . inSampleSize= scaleX;          //设置宽高比为宽

}else if(scaleX < scaleY && scaleX>1){

              option . inSampleSize= scaleY;          //设置宽高比为高

}

 

option . inJustDecodeBounds = false; 

BitmapFactory . decodeFile(url , option);

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值