android - Robolectric getPixel 始终返回 0

标签 android robolectric getpixel

我正在尝试使用 Roboelectic 通过 Bitmap 和 Getpixel 方法运行一些测试: ((BitmapDrawable)Robolectric.application.getResources().getDrawable(R.drawable.color_test_1)).getBitmap().getPixel(100,100); 但无论我尝试什么,我总是得到 0 作为颜色。

即使我使用以下示例:

public void testGetPixelsWithoutAlpha() throws Exception {
    int[] colors = new int[100];
    for (int i = 0; i < 100; i++) {
        colors[i] = i;
    }

    Bitmap bm = Bitmap.createBitmap(colors, 10, 10, Bitmap.Config.RGB_565);


    int[] pixels = new int[100];
    bm.getPixels(pixels, 0, 10, 0, 0, 10, 10);
    for (int i = 0; i < 100; i++) {
        int p = bm.getPixel(i % 10, i / 10);
        System.out.println(p);
        assertEquals("getPixels", p, pixels[i]);
    }

我得到的像素仍然是 0。

最佳答案

遗憾的是,我不认为有一种方法可以在 Robolectric 中进行此类测试。 Bitmap 有趣的部分是 native 代码,Robolectric 不会运行它。因此,像素实际上并未设置或更改。

关于android - Robolectric getPixel 始终返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24258801/

相关文章:

android - 我可以使用 Robolectric 对静态库 jar 进行单元测试吗?

Robolectric 3.2.2 获取影子类的实例?

java - EasyMock + Roboelectric + 类模拟

android - 如何在android项目的res文件夹中获取图像的像素

android - 无法在 VMWare 中运行 Genymotion

android - Android SDK 中的 SQLite 源代码

java - 将 InputStream 转换为 JSONObject

Android 4.4.2 - 相机 uri 返回 null 并且裁剪功能不起作用?

python - 从背景窗口获取像素颜色