2017-12-28 3 views
0

애셋 안드로이드에서 image.png에서 치수를 얻는 방법은 무엇입니까?애셋 Android에서 크기 이미지 가져 오기

시도해 보았지만 작동하지 않습니다.

String image = "my_image.png" 
 

 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
 
    options.inJustDecodeBounds = true; 
 
    BitmapFactory.decodeFile(context.getAssets() + "/" + image, options); 
 
// BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getPath() + "/other_dir/" + image, options); 
 

 
    int width_t = options.outWidth; 
 
    int height_t = options.outHeight;

이미지/other_dir /에, 내가 크기를 얻을 수 있지만 자산에 할 수있는 경우.

답변

0

이 시도 :

AssetManager asset = context.getAssets(); 
InputStream is; 
try { 
    is = asset.open("my_image.png"); 
} catch (IOException e) { 
return null; 
} 
BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inJustDecodeBounds = true; 
BitmapFactory.decodeStream(is, null, options); 

int width_t = options.outWidth; 
int height_t = options.outHeight; 
+0

완벽한 작품, 감사합니다. 내가 변경 : InputStream is = null; – canel

관련 문제