Ich habe sowohl die externen Lese-und Schreibrechte und angeforderte Berechtigung für sie vom Benutzer hinzugefügt. Ich habe das libgdx-Dateisystem verwendet, um eine Liste von Dateihandles von Bildern zu erstellen, die ich laden möchte. Ich lade sie wie folgt:Libgdx laden Textur von Gdx.files.external() zeigt als schwarze Rechtecke
Wenn ich eines der Bilder rendern rendere ich es nur ein schwarzes Rechteck gerendert. Ich render sie nur mit einem Sprite-Batch mit der .draw-Methode, wie ich es normalerweise tun würde. Irgendeine Idee, warum sie als schwarze Rechtecke rendern? Vielen Dank im Voraus/
Mein Bild Modulcode:
package com.ggi.uparty.ui;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.ggi.uparty.screens.ImagePicker;
public class ImagePickerModule {
public ImagePicker p;
public FileHandle fh;
public Texture image = null;
public TextureRegion load,preview;
public float theta = 0;
public Rectangle bounds = new Rectangle();
public ImagePickerModule(ImagePicker p, final FileHandle fh){
theta = 0;
bounds.width=.85f*Gdx.graphics.getWidth()/6f;
bounds.height=bounds.width;
load = new TextureRegion(p.u.assets.get("UI/Load.png", Texture.class));
Thread t = new Thread(new Runnable(){
@Override
public void run() {
try{
//image = new Texture(fh);
image = new Texture(fh);
System.out.println(fh.path());
float sqSize = image.getWidth()<image.getHeight()?image.getWidth():image.getHeight();
preview = new TextureRegion(image,bounds.x+bounds.width/2-sqSize/2,bounds.y+bounds.height/2-sqSize/2,sqSize,sqSize);
}catch(Exception e){
e.printStackTrace();
}
}
});
t.start();
}
public void draw(SpriteBatch pic,float fade){
theta++;
pic.setColor(1, 1, 1, fade);
if(image == null){
pic.draw(load, bounds.x+bounds.width/2 - bounds.height/4, bounds.y + bounds.height/4+theta, bounds.height/4,
bounds.height/4, bounds.height/2, bounds.height/2, 1, 1, -theta);
}
else{
pic.draw(image,bounds.x,bounds.y+theta,bounds.width,bounds.height);
}
}
}
Wahrscheinlich Zusammenhang Verlust, aber es ist unmöglich zu sagen, von dieser 1 Codezeile:
dann asynchroner Laden implementieren einen Assetmanager zu erhalten. –
@ p.streef hinzugefügt den Code mit dem Laden und Anzeigen –