Exemplo n.º 1
0
  /**
   * 描述:通过文件的本地地址从SD卡读取图片.
   *
   * @param file the file
   * @param type 图片的处理类型(剪切或者缩放到指定大小,参考AbConstant类) 如果设置为原图,则后边参数无效,得到原图
   * @param desiredWidth 新图片的宽
   * @param desiredHeight 新图片的高
   * @return Bitmap 新图片
   */
  public static Bitmap getBitmapFromSD(File file, int type, int desiredWidth, int desiredHeight) {
    Bitmap bitmap = null;
    try {
      // SD卡是否存在
      if (!isCanUseSD()) {
        return null;
      }

      // 文件是否存在
      if (!file.exists()) {
        return null;
      }

      // 文件存在
      if (type == AbImageUtil.CUTIMG) {
        bitmap = AbImageUtil.getCutBitmap(file, desiredWidth, desiredHeight);
      } else if (type == AbImageUtil.SCALEIMG) {
        bitmap = AbImageUtil.getScaleBitmap(file, desiredWidth, desiredHeight);
      } else {
        bitmap = AbImageUtil.getBitmap(file);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return bitmap;
  }
Exemplo n.º 2
0
 /**
  * 描述:根据URL从互连网获取图片.
  *
  * @param url 要下载文件的网络地址
  * @param type 图片的处理类型(剪切或者缩放到指定大小,参考AbConstant类)
  * @param desiredWidth 新图片的宽
  * @param desiredHeight 新图片的高
  * @return Bitmap 新图片
  */
 public static Bitmap getBitmapFromURL(String url, int type, int desiredWidth, int desiredHeight) {
   Bitmap bit = null;
   try {
     bit = AbImageUtil.getBitmap(url, type, desiredWidth, desiredHeight);
   } catch (Exception e) {
     AbLogUtil.d(AbFileUtil.class, "下载图片异常:" + e.getMessage());
   }
   return bit;
 }
Exemplo n.º 3
0
  /**
   * 描述:通过文件的本地地址从SD卡读取图片.
   *
   * @param file the file
   * @return Bitmap 图片
   */
  public static Bitmap getBitmapFromSD(File file) {
    Bitmap bitmap = null;
    try {
      // SD卡是否存在
      if (!isCanUseSD()) {
        return null;
      }
      // 文件是否存在
      if (!file.exists()) {
        return null;
      }
      // 文件存在
      bitmap = AbImageUtil.getBitmap(file);

    } catch (Exception e) {
      e.printStackTrace();
    }
    return bitmap;
  }