3
votes

I have a GUI built app, that manages profiles of clients. When a new profile is created, a picture is taken. The path (String) is saved in a Hashtable along with the other info.

When it displays the list of all clients, each client info is set in a Multibutton, each containing a small picture of the client. That picture is a masked picture that is set every time the form is loaded, making it very slow to load (when I didn't have the small pictures, it loaded faster).

enter image description here

Question

I would like to save the masked small picture right after I take & save the picture of the client. So when I display the list of clients, I would just fetch the small image instead of having to do the masking for all the items. Is this possible?

I am trying this: (my goal is to have a working "smallPhotoPath")

String bigPhotoPath = Capture.capturePhoto(width, -1);
Image bigPhoto = Image.createImage(bigPhotoPath);
...
//masking image
...
bigPhoto = bigPhoto.applyMask(mask);

String smallPhotoPath = bigPhotoPath+"Small";
Image smallPhoto = bigPhoto.scaled(bigPhoto.getWidth()/8, -1);
java.io.OutputStream os = Storage.getInstance().createOutputStream(smallPhotoPath);
ImageIO.getImageIO().save(smallPhoto, os, ImageIO.FORMAT_PNG, 1);
os.close();
1
I don't understand what's not working in your code snippet? Notice that you need to remove the mask from the label/multibutton if the image is pre-masked. - Shai Almog
when I later try to use "Image.createImage(smallPhotoPath)" in order to load the small picture into the Multibutton, it doesn't work, and an error is caught - Felipe
Shai, is it possible to use EncodedImage for this? I checked your ChatApp tutorial, but there you replace the EncodedImage with a URLImage. Can I do the same. but for a Captured Image instead of an image from the web? - Felipe
EncodedImage just loads an image with a file so in terms of functionality it isn't very different from Image. We explain a lot of the differences between image types here: codenameone.com/manual/graphics.html#deep-into-images-section - Shai Almog

1 Answers

2
votes

After experimenting a lot, I solved the issue. I changed the following line:

java.io.OutputStream os = Storage.getInstance().createOutputStream(smallPhotoPath);

for this one:

OutputStream os = FileSystemStorage.getInstance().openOutputStream(smallPhotoPath);

Now it works fine :)