예제 #1
0
  public Bitmap loadImage(String path) throws OutOfMemoryError {
    Bitmap bitsat;

    try {
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inPreferredConfig = Bitmap.Config.ARGB_8888;
      options.inJustDecodeBounds = true;
      Bitmap b = BitmapFactory.decodeFile(path, options);

      options.inSampleSize = Futils.calculateInSampleSize(options, px, px);

      // Decode bitmap with inSampleSize set
      options.inJustDecodeBounds = false;

      Bitmap bit;
      if (path.startsWith("smb:/")) bit = BitmapFactory.decodeStream(new SmbFileInputStream(path));
      else bit = BitmapFactory.decodeFile(path, options);

      bitsat =
          bit; // decodeFile(path);//.createScaledBitmap(bits,imageViewReference.get().getHeight(),imageViewReference.get().getWidth(),true);
    } catch (Exception e) {
      Drawable img = ContextCompat.getDrawable(mContext, R.drawable.ic_doc_image);
      Bitmap img1 = ((BitmapDrawable) img).getBitmap();
      bitsat = img1;
    }
    return bitsat;
  }
예제 #2
0
 public static Bitmap getSmallBitmap(String filePath, int reqWidth, int reqHeight) {
   BitmapFactory.Options options = new BitmapFactory.Options();
   options.inJustDecodeBounds = true;
   BitmapFactory.decodeFile(filePath, options);
   options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
   options.inJustDecodeBounds = false;
   return BitmapFactory.decodeFile(filePath, options);
 }
 static void calculateInSampleSize(
     int paramInt1,
     int paramInt2,
     int paramInt3,
     int paramInt4,
     BitmapFactory.Options paramOptions,
     Request paramRequest) {
   int i = 1;
   if ((paramInt4 > paramInt2) || (paramInt3 > paramInt1)) {
     if (paramInt2 != 0) {
       break label43;
     }
   }
   for (i = (int) Math.floor(paramInt3 / paramInt1);
       ;
       i = (int) Math.floor(paramInt4 / paramInt2)) {
     paramOptions.inSampleSize = i;
     paramOptions.inJustDecodeBounds = false;
     return;
     label43:
     if (paramInt1 != 0) {
       break;
     }
   }
   paramInt2 = (int) Math.floor(paramInt4 / paramInt2);
   paramInt1 = (int) Math.floor(paramInt3 / paramInt1);
   if (paramRequest.centerInside) {}
   for (i = Math.max(paramInt2, paramInt1); ; i = Math.min(paramInt2, paramInt1)) {
     break;
   }
 }
 /**
  * @Method: decodeBitmap @Description: ���ļ��ж�ȡͼƬ
  *
  * @param path ͼƬ��·��
  * @return
  */
 Bitmap decodeBitmap(String path) {
   BitmapFactory.Options op = new BitmapFactory.Options();
   op.inJustDecodeBounds = true;
   Bitmap bmp = BitmapFactory.decodeFile(path, op);
   int wRatio = (int) Math.ceil(op.outWidth / 100); // ��ȡ�����С
   int hRatio = (int) Math.ceil(op.outHeight / 100);
   if (wRatio > 1 && hRatio > 1) { // ����ָ����С������С��Ӧ�ı���
     if (wRatio > hRatio) {
       op.inSampleSize = wRatio;
     } else {
       op.inSampleSize = hRatio;
     }
   }
   op.inJustDecodeBounds = false;
   bmp = BitmapFactory.decodeFile(path, op);
   return bmp;
 }
예제 #5
0
  /**
   * Stores a bitmap for use by a game tile in a level.
   *
   * @param int resourceId - The bitmap resource ID.
   * @return Bitmap - The Bitmap instance for the given resource ID.
   */
  private Bitmap setAndGetGameTileBitmap(int resourceId) {
    if (!mGameTileBitmaps.containsKey(resourceId)) {
      BitmapFactory.Options opts = new BitmapFactory.Options();
      opts.inJustDecodeBounds = true;
      Bitmap bitmap = BitmapFactory.decodeResource(mGameContext.getResources(), resourceId);

      if (bitmap != null) {
        mGameTileBitmaps.put(resourceId, bitmap);
      }
    }

    return mGameTileBitmaps.get(resourceId);
  }
예제 #6
0
  /**
   * @Method: decodeBitmap @Description: ��ȡpath·���µ�ͼƬ��������
   *
   * @param path
   * @param rect
   * @return
   */
  Bitmap decodeBitmap(String path, int rect) {
    BitmapFactory.Options op = new BitmapFactory.Options();
    op.inJustDecodeBounds = true;
    op.inPreferredConfig = Bitmap.Config.ALPHA_8;
    Bitmap bmp = BitmapFactory.decodeFile(path, op);
    // ��ȡ�����С
    int wRatio = (int) Math.ceil(op.outWidth / rect);
    int hRatio = (int) Math.ceil(op.outHeight / rect);

    // ����ָ����С������С��Ӧ�ı���
    if (wRatio > 1 && hRatio > 1) {
      if (wRatio > hRatio) {
        op.inSampleSize = wRatio;
      } else {
        op.inSampleSize = hRatio;
      }
    }
    op.inPreferredConfig = Bitmap.Config.ALPHA_8;
    op.inJustDecodeBounds = false;
    bmp = BitmapFactory.decodeFile(path, op);
    return bmp;
  }
 static BitmapFactory.Options createBitmapOptions(Request paramRequest) {
   boolean bool = paramRequest.hasSize();
   if (paramRequest.config != null) {}
   for (int i = 1; ; i = 0) {
     Object localObject = null;
     if ((bool) || (i != 0)) {
       BitmapFactory.Options localOptions = new BitmapFactory.Options();
       localOptions.inJustDecodeBounds = bool;
       localObject = localOptions;
       if (i != 0) {
         localOptions.inPreferredConfig = paramRequest.config;
         localObject = localOptions;
       }
     }
     return (BitmapFactory.Options) localObject;
   }
 }