Share Bitmap ressources into a thread
in
Programming Questions
•
6 months ago
Hello, sorry I'm still stuck into loading images in a very efficient way.
I use the really nice class from quarks. I need to display pictures according to their name which the class do very well with hashmap.
I need to put this into a thread to display pictures which are already into the ram, while loading and removing the others one from the ram without delay.
that is my problem, I can't make it works here's the code of modified class:
I use the really nice class from quarks. I need to display pictures according to their name which the class do very well with hashmap.
I need to put this into a thread to display pictures which are already into the ram, while loading and removing the others one from the ram without delay.
that is my problem, I can't make it works here's the code of modified class:
- import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import processing.core.PApplet;
import processing.core.PImage;
String filename;
class Textures_loader extends Thread
{
Textures_loader(PApplet app, String _filename)
{
_filename = filename;
}
public PImage loadImage(PApplet app, String filename) {
HashMap<String, PImage> textures = new HashMap<String, PImage>();
if (textures.containsKey(filename)) {
return textures.get(filename);
}
PImage image = app.loadImage(filename);
if (image != null) {
textures.put(filename, image);
Iterator i = textures.entrySet().iterator(); // Get an iterator
while (i.hasNext ()) {
Map.Entry me = (Map.Entry)i.next();
// PApplet.print(me.getKey() + " is "); //this is a way to know the image object loaded.
// PApplet.println(me.getValue());
}
}
else
PApplet.println("Unable to load image from file '" + filename+"'");
return image;
}
public void run()
{
try {
Textures_loader.loadImage(PApplet app, String filename);
}
catch (Exception e) {
println("No Video Image: "+ e);
}
}
}
It must be full of errors…I cant debug it, not sure enough about my abilities to do it. A little help would be really appreciated (it's been 20 days I am on this issue…
)
thanks in advance
thanks in advance
1