Android setPixels返回黑色

时间:2011-11-29 19:03:08

标签: android opengl-es android-canvas

我有以下功能:

private void clearScreen(int color)
{
    fOffscreenImage.eraseColor(color);
}

private void fillRect(int x, int y, int width, int height, int color)
{
    for(;x<width;x++)
    {
        for(;y<height;y++)
        {
            buffer[x+y*PROJECTIONPLANEWIDTH] = color;
        }
    }
}

private void drawBuffer()
{
    fOffscreenImage.setPixels(buffer,0,PROJECTIONPLANEWIDTH,0,0,PROJECTIONPLANEWIDTH,PROJECTIONPLANEHEIGHT);
}

两个函数都绘制到一个位图,首先是eraseColor,它工作正常,第二个是setPixels,它总是返回黑色。我正在将图像写入使用OpenGL显示的四边形。作为颜色输入我尝试了默认颜色(Color.BLUE)和Color.argb。 getPixel会返回相关颜色的正确输出。

对setPixel的逐个像素调用也不起作用,它会忽略该作业。

我尝试使用Android 2.1和2.3。

对此的任何建议都会很棒..

3 个答案:

答案 0 :(得分:0)

我用以下fillRect代码替换了部分raycaster,它现在在适当的位置显示白线! 现在只是为了找出其他颜色:)

private void fillRect(int x, int y, int width, int height, int color)
{
    width += x;
    height += y;
    for(;x<width;x++)
    {
        for(;y<height;y++)
        {
            if (x+y*PROJECTIONPLANEWIDTH < PROJECTIONPLANEHEIGHT*PROJECTIONPLANEWIDTH)
                buffer[x+y*PROJECTIONPLANEWIDTH] = color;
        }
    }
}

答案 1 :(得分:0)

我通过不使用setPixel修复此问题,而是使用canvas绘制到位图。然而它已经慢了......

答案 2 :(得分:0)

private void fillRect(int x, int y, int width, int height, int color)
{
    width += x;
    height += y;
    for(;x<width;x++)
    {
        for(;y<height;y++)
        {
            buffer[x+y*PROJECTIONPLANEWIDTH] = color;
        }
    }
}

应该是

private void fillRect(int x, int y, int width, int height, int color)
{
    width += x;
    height += y;
    for(int y2 = y;y2<height;y2++)
    {
        for(int x2 = x;x2<width;x2++)
        {
            buffer[x2+y2*PROJECTIONPLANEWIDTH] = color;
        }
    }
}
相关问题