Androidで画像サイズを取得する2つの方法

1275 ワード

2つの方法は2つ目の方法を提案する.
   private void getPictureSize(String path) {

        /*      bitmap      ,   bitmap   ,
            ,               ,
              ,    OOM;*/
        //   :  uri      bitmap   
        Bitmap bitmap = BitmapFactory.decodeFile(path);
        int height = bitmap.getHeight();
        int width = bitmap.getWidth();
        Log.i("xg", "  bitmap        " + "width: " + width + " height: " + height);


        /*bitmap.options  bitmap    ,       bitmap   ;
                        ,   bitmap     ,
                  bitmap     。*/
        //   :  Options    
        //inJustDecodeBounds If set to true, the decoder will return null (no bitmap)
        //      ,    bitmap  ,
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;//       true   ,
        Bitmap bmp = BitmapFactory.decodeFile(path, options);//   bitmap   
        if (bmp == null) {
            Log.e("xg", "  options    bitmap   ===");
        }
        int outHeight = options.outHeight;
        int outWidth = options.outWidth;
        Log.i("xg", "  Options        " + "width:" + outWidth + " height: " + outHeight);

    }