我试图通过转换将位图转换为libGDX纹理:
Bitmap到byte[]byte[] 到libGDX PixmapPixmap到libGDXTexture我面临的问题是转换为纹理的位图是从属性文件夹中的纹理包装器绘制精灵表
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();
}
}
Run Code Online (Sandbox Code Playgroud)
And*_*iue 17
如果目标是将Android位图转换为libgdx纹理,则根本不需要使用Pixmap.您可以在简单的OpenGL和Android GLUtils的帮助下直接完成.尝试以下方法; 它比您的解决方案快100倍.我假设你不在渲染线程中(你最不可能).如果是,则不需要调用postRunnable().
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
Texture tex = new Texture(bitmap.getWidth(), bitmap.getHeight(), Format.RGBA8888);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.getTextureObjectHandle());
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
bitmap.recycle();
// now you have the texture to do whatever you want
}
});
Run Code Online (Sandbox Code Playgroud)
小智 12
另一种可能性是你有一个线程问题.我在UI线程上加载我自己的非托管纹理时注意到了这种问题,而libgdx在渲染线程上同时加载纹理.如果这是问题,那么简单的解决方案是使用Gdx.app.postRunnable将纹理的创建与渲染线程同步.即:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5544 次 |
| 最近记录: |