大图处理

来源:互联网 发布:js代码压缩工具 编辑:程序博客网 时间:2024/04/29 00:12

大图处理

闲着没事写的一个方法

 public Bitmap getTargetBitmap(int iamgeResource,int targetWidth,int targetHeight) {    BitmapFactory.Options options = new BitmapFactory.Options();    //设置options    options.inJustDecodeBounds = true;    BitmapFactory.decodeResource(getResources(),iamgeResource,options);    int outWidth = options.outWidth;    int outHeight = options.outHeight;    //计算宽高比    int widthB = outWidth / targetWidth;    int heightB = outHeight / targetHeight;    //使用合适的比例    int targetComple = widthB > heightB ? widthB : heightB;    //重新设置options    options.inSampleSize = targetComple;    options.inJustDecodeBounds = false;    return BitmapFactory.decodeResource(getResources(),iamgeResource,options);}
0 0