zoukankan      html  css  js  c++  java
  • [android]加载大量图片避免OOM

    原理是事先取得图片的长宽,直接读出缩略图.

    BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888; // 默认是Bitmap.Config.ARGB_8888
            // 下面两个字段需要组合使用
            options.inPurgeable = true;

    options.inInputShareable = true;

             options.inJustDecodeBounds = true;//true和false之间获得长宽和缩放比例
             BitmapFactory.decodeFile(filepath, options);
             int wRatio = (int) Math.ceil(options.outWidth /(unit_width * PtsPerUnitPic));
             int hRatio = (int) Math.ceil(options.outHeight /( unit_height * PtsPerUnitPic));
             // 如果超出指定大小,则缩小相应的比例
             if (wRatio > 1 && hRatio > 1) {
             if (wRatio > hRatio) {
             options.inSampleSize = wRatio;
             System.out.println(wRatio);
             } else {
             options.inSampleSize = hRatio;
             System.err.println(hRatio);
             }
             }else {
                return;
            }         
             options.inJustDecodeBounds = false;
     
            temp_unit_bitmap = BitmapFactory.decodeFile(filepath, options);
  • 相关阅读:
    smobiler仿京东app搜索页面
    搜索界面设计
    smobiler仿饿了么app筛选页面
    Smobiler低功耗蓝牙连接的过程和参数的含义
    smobiler仿饿了么app搜索页面
    内存分配的几个函数的简单对比分析
    Android仿IOS选择拍照相册底部弹出框
    正则表达式 : 6~16位字符,至少包含数字.字母.符号中的2种
    android 音量键调节无效问题
    windows查看系统过期时间
  • 原文地址:https://www.cnblogs.com/zeyang/p/3606033.html
Copyright © 2011-2022 走看看