单元测试中的BitmapFactory.decodeResource始终返回32像素的宽度和高度

时间:2017-11-08 13:09:39

标签: android unit-testing bitmap pixel

我正在编写一个单元测试,首先我需要测试给定资源的宽度和高度,然后再使用它进一步断言。但是,无论像素是什么? 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像素。

为什么仅在单元测试期间发生此行为?我无法找到任何合理的解释。

0 个答案:

没有答案