转换的Andr​​oid位图到LibGdx的纹理位图、纹理、Andr、oid

2023-09-12 22:43:03 作者:古城老巷°少年已去

我试图通过转换为位图转换成一个libGDX质地:

Android的位图字节[] 字节[] 来libGDX的 像素图 libGDX 像素图来libGDX 纹理

我现在面临的问题是,将其转化为纹理位图是借鉴纹理包装是资产文件夹中的精灵表

 公共无效onByteArrayOfCroppedImageReciever(byte []的字节){
    尝试 {
        PMAP =新像素图(字节,0,bytes.length);
        TEX =新的纹理(PMAP);
        FACE =新的Sprite(TEX);
        // game.setScreen(新GameScreen(游戏,配料,面));
    }赶上(例外五){
        Gdx.app.log(KS,e.toString());
        e.printStackTrace();
    }
}
 

解决方案

嗯另一种可能是,你有一个线程问题。加载自己的非托管的纹理时,在UI线程上,而libgdx是同时做的事情装载纹理渲染线程上,我注意到这样的问题。 如果这是问题的简单的解决方案是同步建立使用Gdx.app.postRunnable渲染线程的纹理。即:

 公共无效onByteArrayOfCroppedImageReciever(byte []的字节){
    尝试 {
        PMAP =新像素图(字节,0,bytes.length);
        Gdx.app.postRunnable(新的Runnable(){
            @覆盖
            公共无效的run(){
                TEX =新的纹理(PMAP);
                FACE =新的Sprite(TEX);
            }
        });
    }赶上(例外五){
        Gdx.app.log(KS,e.toString());
        e.printStackTrace();
    }
}
 

i am trying to convert bitmap into a libGDX Texture by converting:

Android Bitmap to byte[] byte[] to libGDX Pixmap libGDX Pixmap to libGDX Texture

The problem I am facing is that the bitmap which is converted to texture is drawing the sprite sheet from texture packer that is in assets folder

public void onByteArrayOfCroppedImageReciever(byte[] bytes) {
    try {
        pmap=new Pixmap(bytes, 0, bytes.length);
        tex=new Texture(pmap);
        face=new Sprite(tex);
        // game.setScreen(new GameScreen(game, batcher, face));
    } catch(Exception e) {
        Gdx.app.log("KS", e.toString());
        e.printStackTrace();
    }
}

解决方案

hmm another possibility is that you've got a threading issue. I've noticed this kind of problem when loading my own unmanaged textures on the UI thread while libgdx is doing its thing loading textures concurrently on the render thread. If this is the problem the simple solution is to synchronize the creation of the texture with the render thread using Gdx.app.postRunnable. i.e.:

public void onByteArrayOfCroppedImageReciever(byte[] bytes) {
    try {
        pmap=new Pixmap(bytes, 0, bytes.length);
        Gdx.app.postRunnable(new Runnable() {
            @Override
            public void run() {            
                tex=new Texture(pmap);
                face=new Sprite(tex);
            }
        });
    } catch(Exception e) {
        Gdx.app.log("KS", e.toString());
        e.printStackTrace();
    }
}