libgdx TextureRegion到Pixmap [英] libgdx TextureRegion to Pixmap

查看:118
本文介绍了libgdx TextureRegion到Pixmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从TextureRegion或Sprite创建Pixmap?我需要这样做,以便更改某些像素的颜色,然后从Pixmap创建新的Texture(在加载屏幕期间).

How do I create Pixmap from TextureRegion or from Sprite? I need this in order to change color of some pixels and then create new Texture from Pixmap (during loading screen).

推荐答案

Texture texture = textureRegion.getTexture();
if (!texture.getTextureData().isPrepared()) {
    texture.getTextureData().prepare();
}
Pixmap pixmap = texture.getTextureData().consumePixmap();

如果只需要该纹理的一部分(该区域),则必须进行一些手动处理:

If you want only a part of that texture (the region), then you'll have to do some manual processing:

for (int x = 0; x < textureRegion.getRegionWidth(); x++) {
    for (int y = 0; y < textureRegion.getRegionHeight(); y++) {
        int colorInt = pixmap.getPixel(textureRegion.getRegionX() + x, textureRegion.getRegionY() + y);
        // you could now draw that color at (x, y) of another pixmap of the size (regionWidth, regionHeight)
    }
}

这篇关于libgdx TextureRegion到Pixmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆