Fork us on GitHub

Image Viewer From The Web

I've been working on demos for JavaZone and built something s...

Image Viewer From The Web

Picture
I've been working on demos for JavaZone and built something small that has been asked a few times. Some developers were looking for URLImage support in image viewer but that's not a very good approach since URLImage expects images to be at a specific resolution and is thus very bad for images with unknown dimensions. However, ImageViewer thrives on showing and zooming full sized images.
There was a bit of a community hack with ImageDownloadService a while back but it was a bit in-elegant and wasn't what I was looking for, so I created a simple list model that just streams images, you can use it with image viewer like this:
                ImageViewer viewer = new ImageViewer(imageList.getItemAt(offset));
                viewer.setImageList(imageList);

The list model is just a plain old list model that expects the placeholder image to be an encoded image you have already loaded. This implementation expects images to have an ID which we use in the createImageURL method. Notice we could just use the image index but since that might change (user deletes images etc.) we needed to have ID's generated by the server. We'll have the full demo up with the server side code for JavaZone:

Notice: This post was automatically converted using a script from an older blogging system. Some elements might not have come out as intended.... If that is the case please let us know via the comments section below.

Share this Post:

Posted by Shai Almog

Shai is the co-founder of Codename One. He's been a professional programmer for over 25 years. During that time he has worked with dozens of companies including Sun Microsystems.
For more follow Shai on Twitter & github.