Пример #1
0
  public static Bitmap getSmallAvatarWithRoundedCorner(String url, int reqWidth, int reqHeight) {

    if (!FileManager.isExternalStorageMounted()) {
      return null;
    }

    String absoluteFilePath = FileManager.getFilePathFromUrl(url, FileLocationMethod.avatar_small);
    absoluteFilePath = absoluteFilePath + ".jpg";

    Bitmap bitmap = BitmapFactory.decodeFile(absoluteFilePath);

    if (bitmap == null && !SettingUtility.isEnablePic()) {
      return null;
    }

    if (bitmap == null) {
      boolean result = getBitmapFromNetWork(url, absoluteFilePath, null);
      if (result) bitmap = BitmapFactory.decodeFile(absoluteFilePath);
    }

    if (bitmap != null) {
      if (bitmap.getHeight() < reqHeight || bitmap.getWidth() < reqWidth) {
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true);
        Bitmap roundedBitmap = ImageEdit.getRoundedCornerBitmap(scaledBitmap);
        bitmap.recycle();
        scaledBitmap.recycle();
        return roundedBitmap;
      }
    }

    return null;
  }
Пример #2
0
  public static Bitmap getTimeLineBigAvatarWithRoundedCorner(
      String url, int reqWidth, int reqHeight) {

    if (!FileManager.isExternalStorageMounted()) {
      return null;
    }

    String absoluteFilePath = FileManager.getFilePathFromUrl(url, FileLocationMethod.avatar_large);
    absoluteFilePath = absoluteFilePath + ".jpg";

    boolean fileExist = new File(absoluteFilePath).exists();

    if (!fileExist && !SettingUtility.isEnablePic()) {
      return null;
    }

    if (!fileExist) {
      boolean result = getBitmapFromNetWork(url, absoluteFilePath, null);
      if (!result) return null;
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(absoluteFilePath, options);

    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;
    options.inInputShareable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(absoluteFilePath, options);

    if (bitmap != null) {
      Bitmap roundBitmap = ImageEdit.getRoundedCornerBitmap(bitmap);
      bitmap.recycle();
      return roundBitmap;
    }

    return bitmap;
  }
Пример #3
0
  public static Bitmap getBigAvatarWithRoundedCorner(String url) {

    if (!FileManager.isExternalStorageMounted()) {
      return null;
    }

    String absoluteFilePath = FileManager.getFilePathFromUrl(url, FileLocationMethod.avatar_large);
    absoluteFilePath = absoluteFilePath + ".jpg";

    Bitmap bitmap = BitmapFactory.decodeFile(absoluteFilePath);

    if (bitmap == null && SettingUtility.isEnablePic()) {
      getBitmapFromNetWork(url, absoluteFilePath, null);
      bitmap = BitmapFactory.decodeFile(absoluteFilePath);
    }

    if (bitmap != null) {
      bitmap = ImageEdit.getRoundedCornerBitmap(bitmap);
    }

    return bitmap;
  }
Пример #4
0
  public static Bitmap getRoundedCornerPic(
      String url, int reqWidth, int reqHeight, FileLocationMethod method) {
    try {

      if (!FileManager.isExternalStorageMounted()) {
        return null;
      }

      String filePath = FileManager.getFilePathFromUrl(url, method);
      if (!filePath.endsWith(".jpg") && !filePath.endsWith(".gif")) filePath = filePath + ".jpg";

      boolean fileExist = new File(filePath).exists();

      if (!fileExist && !SettingUtility.isEnablePic()) {
        return null;
      }

      if (!fileExist) {
        boolean result = getBitmapFromNetWork(url, filePath, null);
        if (!result) return null;
      }

      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(filePath, options);

      options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
      options.inJustDecodeBounds = false;
      options.inPurgeable = true;
      options.inInputShareable = true;

      Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);

      if (bitmap == null) {
        // this picture is broken,so delete it
        new File(filePath).delete();
        return null;
      }

      if (bitmap.getHeight() < reqHeight || bitmap.getWidth() < reqWidth) {

        int[] size = calcResize(bitmap.getWidth(), bitmap.getHeight(), reqWidth, reqHeight);
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, size[0], size[1], true);

        if (scaledBitmap != bitmap) {
          bitmap.recycle();
          bitmap = scaledBitmap;
        }

        Bitmap roundedBitmap = ImageEdit.getRoundedCornerBitmap(bitmap);
        if (roundedBitmap != bitmap) {
          bitmap.recycle();
          bitmap = roundedBitmap;
        }
        return bitmap;
      }

      return bitmap;
    } catch (OutOfMemoryError ignored) {
      ignored.printStackTrace();
      return null;
    }
  }