We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there, I'm using a googleImageLoader library. I got my API key and it worked well. But I want to make user search images they want( The original code was set to find "sunset beach" ). so I changed some codes but they are really new for me that I can't find what is wrong. Is there anyone who can help me, please?
import at.mukprojects.imageloader.*;
import at.mukprojects.imageloader.google.*;
import at.mukprojects.imageloader.image.*;
String apiKey = "--------------- ";
ImageLoader loader;
ImageList list;
Image img;
String search = " ";
void setup() {
size(800, 450);
loader = new GoogleLoader(this, apiKey);
}
void draw() {
textSize(64);
fill(0);
text(search, width/2, height/2); //show typing which image the user want to find
if (mousePressed) {
list = loader.start(search, true, 60 * 1000);
img = list.getRandom();
if (img == null) {
img = list.getRandom();
} else {
image(img.getImg(), 0, 0, width, height);
}
}
}
void keyPressed() {
search += key;
}
Answers
Are you following this link? https://github.com/keshrath/ImageLoader
Can you comment how did you get your api key?
Quick side note:
Remove the code block of mousePressed inside draw(). Instead do this:
Your code could potentially execute as many times as mousePressed is true. My suggestion should work only once. This will not solve the problem but it is more of a technicality.
Kf