zoukankan      html  css  js  c++  java
  • 最省内存的方式加载图片资源

    /**
      * 重载loadBitmap
      * @param res
      * @param id
      * @return
      */
     public static Bitmap loadBitmap(Resources res,int id){

      BitmapFactory.Options opt = new BitmapFactory.Options();
      opt.inPreferredConfig = Bitmap.Config.RGB_565;
      opt.inPurgeable = true;
      opt.inInputShareable = true;
      
      InputStream is = res.openRawResource(id);// 获取资源图片
      return BitmapFactory.decodeStream(is, null, opt);
      
     }
     /**
      * 处理图片加载方式可以避免内存溢出
      * 以最省内存的方式读取本地资源的图片
      * dezhengzhou
      * 12、3、30
      */
     public static Bitmap loadBitmapforoptions(Context context,int id){
       InputStream is = context.getResources().openRawResource(id);
          BitmapFactory.Options options=new BitmapFactory.Options();
          options.inJustDecodeBounds = false;
          options.inSampleSize = 2;   //width,hight设为原来的十分一
          Bitmap btp =BitmapFactory.decodeStream(is,null,options);
      return btp;
      
     }

    上面写了两个类。

    Bitmap oneButtonBitmap ;

    oneButtonBitmap = Util.loadBitmap(
        BaseControl.mContext, R.drawable.select_point_one);

  • 相关阅读:
    javascript Date format(js日期格式化)
    WebService中方法的重载
    win10 剪贴板 拒绝访问 Cannot open clipboard
    win10 剪贴板 拒绝访问
    Image Base64 Datasnap Image delphi与c#互相兼容识别
    app 支付宝 支付 alipaySdk
    Java2OP
    delphi action学习
    FireDAC 超时
    TCheckListBox
  • 原文地址:https://www.cnblogs.com/zdzyc/p/2426453.html
Copyright © 2011-2022 走看看