I upload images over the network and add them to my libgdx user interface as image elements using this:
Pixmap pm = new Pixmap(data, 0, data.length);
Texture t = new Texture(pm);
TextureRegion tr = new TextureRegion(t,200,300);
TextureRegionDrawable trd = new TextureRegionDrawable(tr);
Image icon = new Image();
icon.setDrawable(trd);
Given this, I need some way to reload the texture data, since it gets lost when OpenGL context loses (for example, because the screen goes into sleep mode).
I tried to make my own manager class by adding
DynamicTextureManager.register(t, pm);
to the above snippet, and in resume()I do:
DynamicTextureManager.reload();
Manager class:
public class DynamicTextureManager {
private static LinkedHashMap<Texture, Pixmap> theMap = new
LinkedHashMap<Texture,Pixmap>();
public static void reload() {
Set<Entry<Texture,Pixmap>> es = theMap.entrySet();
for(Entry<Texture,Pixmap> e : es) {
Texture t = e.getKey();
Pixmap p = e.getValue();
t.draw(p, 0, 0);
}
}
public static void register(Texture t, Pixmap p) {
theMap.put(t, p);
}
}
But this does not help - I still get the unloading texture and white areas instead of the image.
How to do it? I could not find any code demonstrating this!