我正在编写一个单元测试,首先我需要测试给定资源的宽度和高度,然后再使用它进一步断言。但是,无论像素是什么? drawable我传递给BitmapFactory.decodeResource
它总是返回Bitmap
,宽度和高度等于 32像素。
Bitmap bmp = BitmapFactory.decodeResource(getContext().getResources(),
com.example.demo.test.R.drawable.big_icon);
assertNotNull("Bitmap is not null", bmp);
Log.d("Test", "Icon Height: " + bmp.getHeight()); // prints 32... why?
Log.d("Test", "Icon Width : ", bmp.getWidth()); // prints 32... why?
我提供的资源( big_icon )位于 drawable-nodpi 文件夹下,为512x512像素。
为什么仅在单元测试期间发生此行为?我无法找到任何合理的解释。