如何正确地将TextureRegion映射到Pixmap?

时间:2017-10-25 09:32:50

标签: java libgdx

我正在尝试将我的纹理区域变成像素图,但是按照准备好的方法将整个图集复制到像素图中,所以我建议循环每个像素并手动将其映射到另一个像素图

    Pixmap emptyPixmap = new Pixmap(trLine.getRegionWidth(), trLine.getRegionHeight(), Pixmap.Format.RGBA8888);

    Texture texture = trLine.getTexture();
    texture.getTextureData().prepare();
    Pixmap pixmap = texture.getTextureData().consumePixmap();

    for (int x = 0; x < trLine.getRegionWidth(); x++) {
        for (int y = 0; y < trLine.getRegionHeight(); y++) {
            int colorInt = pixmap.getPixel(trLine.getRegionX() + x, trLine.getRegionY() + y);
            emptyPixmap.drawPixel( trLine.getRegionX() + x , trLine.getRegionY() + y , colorInt );
        }
    }

    trBlendedLine=new Texture(emptyPixmap);

但生成的纹理没有任何绘制,这意味着getPixel没有获得正确的像素。请指教。

1 个答案:

答案 0 :(得分:1)

您正在使用trLine.getRegionX()+ x和trLine.getRegionY()+ y在像素图之外绘制像素。你应该拥有的是:

for (int x = 0; x < trLine.getRegionWidth(); x++) {
    for (int y = 0; y < trLine.getRegionHeight(); y++) {
        int colorInt = pixmap.getPixel(trLine.getRegionX() + x, trLine.getRegionY() + y);
        emptyPixmap.drawPixel(x , y , colorInt );
    }
}
相关问题