【问题标题】:How to map TextureRegion into Pixmap correctly?如何正确将 TextureRegion 映射到 Pixmap?
【发布时间】:2017-10-26 21:57:08
【问题描述】:

我正在尝试将我的纹理区域制作成像素图,但是通过遵循准备好的方法,它将整个图集复制到像素图中,因此建议我循环每个像素并手动将其映射到另一个像素图中

    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 没有获得正确的像素。请指教。

【问题讨论】:

  • 方法 trLine.getTexture() 获取纹理区域的整个纹理。如果您只想要特定区域,请使用 trLine
  • 你试过这个解决方案了吗:stackoverflow.com/questions/29451787/…
  • @MilanG 是的,我正在尝试这个解决方案,但无法让它与 textureRegion 一起使用
  • @dfour 感谢您的信息,但我需要使用 consumePixmap() 方法将纹理区域映射到像素图

标签: java libgdx


【解决方案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 );
    }
}

【讨论】:

  • 这是我代码中明显的错误,顺便说一句,我意识到像素图要实现我想要的东西非常昂贵,比如从纹理中擦除多边形形状
猜你喜欢
  • 2015-06-09
  • 2014-09-20
  • 2015-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多