본문 바로가기

나의 플랫폼/안드로이드

[Android] 이미지 크기 알아보는 방법

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

/** Get Bitmap's Width **/
  public static int getBitmapOfWidth( String fileName ){
     try {
         BitmapFactory.Options options = new BitmapFactory.Options();
         options.inJustDecodeBounds = true;
         BitmapFactory.decodeFile(fileName, options);
         return options.outWidth;
     } catch(Exception e) {
     return 0;
     }
  }
  
  /** Get Bitmap's height **/
  public static int getBitmapOfHeight( String fileName ){
   
     try {
         BitmapFactory.Options options = new BitmapFactory.Options();
         options.inJustDecodeBounds = true;
         BitmapFactory.decodeFile(fileName, options);
   
         return options.outHeight;
     } catch(Exception e) {
         return 0;
    }
  }