コード例 #1
0
  private Bitmap loadImageFile(final String filename, final AssetManager manager) {
    InputStream is = null;
    try {
      Bitmap bmp = null;
      // Bitmap bmp = BitmapCache.getInstance().getBitmap(filename,
      // param.getAssetManager());
      BufferedInputStream buf;
      try {
        buf = new BufferedInputStream(param.getAssetManager().open(filename));
        bmp = BitmapFactory.decodeStream(buf);

      } catch (IOException e) {

        e.printStackTrace();
      }

      return bmp;
    } catch (Exception e) {
      Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
    } finally {
      try {
        if (is != null) is.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return null;
  }
コード例 #2
0
  @Override
  protected void onPostExecute(Bitmap bitmap) {
    if (isCancelled()) {
      bitmap = null;
    }

    if (imageViewReference != null) {
      final WaterfallFlowView imageView = imageViewReference.get();
      if (imageView != null) {
        if (bitmap != null) {
          int width = bitmap.getWidth(); // 获取真实宽高
          int height = bitmap.getHeight();

          LayoutParams lp = imageView.getLayoutParams();
          lp.height = (height * param.getItemWidth()) / width; // 调整高度
          imageView.setLayoutParams(lp);
          imageView.bitmap = bitmap;
          imageView.setImageBitmap(imageView.bitmap); // 将引用指定到同一个对象,方便销毁

          Handler h = imageView.getViewHandler();
          Message m =
              h.obtainMessage(this.param.what, this.param.getFlowId(), lp.height, imageView);
          h.sendMessage(m);
        }
      }
    }
  }
コード例 #3
0
  @Override
  protected Bitmap doInBackground(WaterfallFlowTag... params) {

    param = params[0];
    return loadImageFile(param.getFileName(), param.getAssetManager());
  }