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 ListView SimpleAdapter 带图片
  2. android -上传文件到服务器
  3. Android之OnGestureListener实现图片的左右滑动
  4. 图片压缩保存读取操作
  5. android gallery相关操作
  6. 安卓课程二十二 ImageView的基本用法
  7. Android——修改开机画面
  8. [android]控件ImageView的常用属性
  9. Android(安卓)圆角图片,基于Glide4.9 的 BitmapTransformation,可

随机推荐

  1. Android(安卓)Log 机制
  2. ok6410 android driver(5)
  3. Android--ListView滚动条样式
  4. android 模拟器
  5. Android(安卓)DNK安装笔记
  6. Android学习07-----事件处理(4)键盘事件
  7. 安卓巴士自测试题-第一期
  8. Android(安卓)Adapter
  9. Android更新真快——Fragment 代替 TabAc
  10. Qt Ubuntu 配置 Android(安卓)环境变量