境界をデコードするだけのオプションをファクトリに渡します。
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
//Returns null, sizes are in the options variable
BitmapFactory.decodeFile("/sdcard/image.png", options);
int width = options.outWidth;
int height = options.outHeight;
//If you want, the MIME type will also be decoded (if possible)
String type = options.outMimeType;
また
ImageView
とを使用してgetWidth()
高さと幅を取得できますがgetHeight()
、これでは画像の正確な幅と高さは得られません。画像の幅の高さを取得するには、まず背景としてドローアブルを取得する必要があり、次にドローアブルを
BitmapDrawable` に変換して取得しますここのように幅と高さを取得できるビットマップとしての画像
Bitmap b = ((BitmapDrawble)imageView.getBackground()).getBitmap();
int w = b.getWidth();
int h = b.getHeight();
またはこのようにする
imageView.setDrawingCacheEnabled(true);
Bitmap b = imageView.getDrawingCache();
int w = b.getWidth();
int h = b.getHeight();
上記のコードはImageview
、デバイスのスクリーンショットのような現在のサイズのビットマップを提供します
ImageView
サイズのみ
imageView.getWidth();
imageView.getHeight();
描画可能な画像があり、そのサイズが必要な場合は、このように取得できます
Drawable d = getResources().getDrawable(R.drawable.yourimage);
int h = d.getIntrinsicHeight();
int w = d.getIntrinsicWidth();