Example #1
0
  public Bitmap getBitmap(Context context, Map<String, String> header) {
    mContext = context;
    // Don't leak context
    if (webImageCache == null) {
      webImageCache = new WebImageCache(context);
    }

    // Try getting bitmap from cache first
    Bitmap bitmap = null;
    if (mUrl != null) {
      bitmap = webImageCache.get(mUrl);
      if (bitmap == null) {
        bitmap = getBitmapFromUrl(mUrl, header);
        if (bitmap != null) {
          webImageCache.put(mUrl, bitmap);
        }
      }
    }
    return bitmap;
  }
Example #2
0
  /** 获取图片 */
  public Bitmap getBitmap(Context context) {
    // Don't leak context
    if (webImageCache == null) {
      webImageCache = new WebImageCache(context);
    }

    // 首先从缓存中获得图片
    Bitmap bitmap = null;
    if (url != null) {
      bitmap = webImageCache.get(url);
      if (bitmap == null && mSmartImageConfig.isDownloadImage) {
        bitmap = getBitmapFromUrl(url);

      } else {
        if (bitmap != null
            && mSmartImageConfig.isAutoRotate
            && bitmap.getWidth() > bitmap.getHeight()) {
          Matrix matrix = new Matrix();
          matrix.postRotate(90);
          bitmap =
              Bitmap.createBitmap(
                  bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
          if (bitmap != null) {
            webImageCache.cacheBitmapToMemory(url, bitmap);
          }
        }
      }
    }

    if (bitmap != null && mSmartImageConfig.isRound) {
      bitmap = toGrayscale(bitmap, 10);
      return bitmap;
    } else {
      return bitmap;
    }
  }