public static Bitmap readBitmap(String path) {        BitmapFactory.Options options = new BitmapFactory.Options();        options.inPreferredConfig = Bitmap.Config.RGB_565;        options.inPurgeable = true;        options.inInputShareable = true;        options.inSampleSize = computeSampleSize(options, -1, 128 * 128);        options.inJustDecodeBounds = true;        // 自行在Android上开辟一段12K大小的内存空间,存储的图片放在该内存中        options.inTempStorage = new byte[12 * 1024];        // 获取资源图片        InputStream is;        try {            is = new FileInputStream(path);            return BitmapFactory.decodeStream(is, null, options);        } catch (FileNotFoundException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        return null;    }    public static int computeSampleSize(BitmapFactory.Options options,            int minSideLength, int maxNumOfPixels) {        int initialSize = computeInitialSampleSize(options, minSideLength,                maxNumOfPixels);        int roundedSize;        if (initialSize <= 8) {            roundedSize = 1;            while (roundedSize < initialSize) {                roundedSize <<= 1;            }        } else {            roundedSize = (initialSize + 7) / 8 * 8;        }        return roundedSize;    }    private static int computeInitialSampleSize(BitmapFactory.Options options,            int minSideLength, int maxNumOfPixels) {        double w = options.outWidth;        double h = options.outHeight;        int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math                .sqrt(w * h / maxNumOfPixels));        int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(                Math.floor(w / minSideLength), Math.floor(h / minSideLength));        if (upperBound < lowerBound) {            return lowerBound;        }        if ((maxNumOfPixels == -1) && (minSideLength == -1)) {            return 1;        } else if (minSideLength == -1) {            return lowerBound;        } else {            return upperBound;        }    }

更多相关文章

  1. Android之OnGestureListener实现图片的左右滑动
  2. 图片压缩保存读取操作
  3. Android 圆角图片,基于Glide4.9 的 BitmapTransformation,可任意设
  4. 【原创】Android 4.4前后版本读取图库图片方式的变化
  5. Android公共库——图片缓存 网络缓存 下拉及底部更多ListView 公
  6. Android RadioButton背景图片和文字的相对位置
  7. Android中高效的显示图片之一 ——加载大图
  8. 华为android 10 手机恢复删除的图片,目前只能恢复小图。
  9. 设置提示信息,输入值类型,输入框引入图片,设置输入框的形状

随机推荐

  1. Termux镜像在阿里云镜像站首发上线
  2. vscode的安装与插件安装,md演示与H5标签功
  3. markdown和html的初体验
  4. Markdown知识点+HTML标签对应功能
  5. markdown的常用语法
  6. Markdown语法小结和HTML标签学习小结
  7. 0316html
  8. 3.16作业
  9. sai怎么画磨砂质感?磨砂质感画法教程
  10. HTML基础标签练习作业