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);
  • 相关阅读:
    mysql 语句case when
    Hibernate应用SQL查询返回实体类型
    JavaBean 和 Map 之间互相转换
    基于注解风格的Spring-MVC的拦截器
    Spring MVC与表单日期提交的问题
    自适应网页设计(Responsive Web Design)
    JSP页面用EL表达式 输出date格式
    EL表达式中如何截取字符串
    DOCTYPE html PUBLIC 指定了 HTML 文档遵循的文档类型定义
    javascript对table的添加,删除行的操作
  • 原文地址:https://www.cnblogs.com/zeyang/p/3606033.html
Copyright © 2011-2022 走看看