[asking] dynamic images with dataProvider

5 messages - 965 views

I have found that the dynamic image with data provider is easily made if the images already on the "img" folder. But how if the source of picture is taken from image file stream?

 

Thanks, kuix project is great!!

 

Picture widget can accept 2 kind of image source :

  • A string : the path to the file in the classpath. If this string starts by a '/' the path is absolute, else, it is relative to the /img/ folder.
  • A byte array : this array represents an image encoded file (like a png or all supported format) @see javax.microedition.lcdui.Image.createImage(byte[] imageData, int imageOffset, int imageLength)

If you want to give imageData to a Picture widget through a Stream, you need to write your own code to read the stream and convert it to a byte[].

I have written my own code to give imageData to a Picture widget. Here is the function code on the DataProvider class:

 

public void setLiveImage(Image liveImage) {

this.liveImage = liveImage;

dispatchUpdateEvent("liveImage");

}

I think the problem is on the XML:  <picture>@{liveImage}</picture>

It seems that the variable  @{liveImage} only accept string or integer. Other objects such an image cannot update its interface (the image did not appear).

 

 

yeah

<picture>@{image}</picture>

the variable @{image} only works for String or integer, when I used it for image, it cannot be change. There is no picture appear..

Hi, please have a look at the picture widget.

there you will find this :

public Picture setImageData(byte[] imageData) {
        if (imageData == null) {
            image = null;
        } else {
            image = Image.createImage(imageData, 0, imageData.length);
        }
        invalidate();
        return this;
    }
So, you can create the the image you want and set it to the picture widget with java code, not in the xml file.

If you want to set the image for a certain picture you have in your xml, just give it an id and then access it form java code.

<picture id="Mypicture"></picture>

and then access to your picture widget by its id, and then set imagedata.