I am looking to make a downloaded image as the background of my form and I'm finding it very hit and miss. Hope someone can help me make it more consistent.
Here is an example of the URL I have as the URL param in my createToStorage call: http://ift.tt/1CHO0mP
and here is the call:
URLImage image = URLImage.createToStorage(placeholder, imageId, imageUrl, URLImage.RESIZE_SCALE);
image.fetch();
I'm setting as background like this:
Container contentPane = getForm().getContentPane();
contentPane.getUnselectedStyle().setBgImage(image);
contentPane.getUnselectedStyle().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
and sometimes the image is downloaded to storage and presented as background but most of the time it isn't so I decided to add a timer to continue calling the image until it's ready so here's what I have:
final URLImage image = URLImage.createToStorage(placeholder, imageId, imageUrl, URLImage.RESIZE_SCALE);
image.fetch();
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
image.fetch();
//image data will be different to placeholder data when successful
if(placeholder.getImageData() != image.getImageData()){
timer.cancel();
Container contentPane = getForm().getContentPane();
contentPane.getUnselectedStyle().setBgImage(image);
contentPane.getUnselectedStyle().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
}
}
},0,3000);
The issue with calling image.fetch() is that it's already fetching so it's not doing anything more there. The placeholder image data is always the same as the image data so the timer will never stop. I could call image.animate() as the check to repaintImage but it doesn't return true. These images will download when included in a list renderer but that's no good for me here. Likewise for really small images, it's more consistent. I may be missing something here but have tried many ways to get these images and none of them are consistent enough to be usable. It may be that I'm calling a service that delivers the image as opposed to it just being on the server. Has anyone been through this already?
Aucun commentaire:
Enregistrer un commentaire