wei-spring / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

URLImage and Label's Background image #1145

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Tested on Simulator (Skin iPhone & Nexus).
Tested on 5S.
Not using the new VM or the new Graphics Pipeline.

What steps will reproduce the problem?
1. Create a new CN1 project.
2. In the state machine class, in the protected void postMain(final Form f) 
method, add the code as below.

Image imu = URLImage.createToStorage(
    encodedPlaceHolder, 
    "bgjpg", URL, 
    URLImage.RESIZE_SCALE
);
f.setLayout(new LayeredLayout());

Label l = new Label("");
l.getUnselectedStyle().setBgColor(0xFF0000);
l.getUnselectedStyle().setBgImage(imu);
l.getUnselectedStyle().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
l.getUnselectedStyle().setBgTransparency(255);
l.setSelectedStyle(l.getUnselectedStyle());
f.addComponent(l);

With encodedPlaceHolder your placeholder and URL the url of the picture you 
want to display.

What is the expected output? What do you see instead?
I expect to see, inside my red label the downloaded picture in its background.
I just see my red label without a background picture.

What version of the product are you using? On what operating system?
IDE: Netbeans 7.4 Patch 3
Java: 1.7.0_51; Java HotSpot(TM) 64-Bit Server VM 24.51-b03
Runtime: Java(TM) SE Runtime Environment 1.7.0_51-b13
System: Mac OS X version 10.9.3 running on x86_64; UTF-8; fr_FR (nb)

CN1 Version: latest.
Pro account: cn1@virttrade.com

Please provide any additional information below.

I can provide our Netbeans Project if easier. I haven't yet since the zip file 
is more than 20Mb.

Original issue reported on code.google.com by fabri...@virttrade.com on 23 Jun 2014 at 10:06

GoogleCodeExporter commented 9 years ago
At the time when you load the image, its data won't we loaded yet.  You need to 
poll the image, and refresh the label once it is received.

if ( imu.isAnimation() && imu.getImageData() == null ){
   // set timer to poll.....
}

// And inside the timer's run

if ( imu.animate() ){
      // repaint the label, or the form, or anything that uses the image
      // and turn off the timer.
}

Note, you'll want your image to be at least an EncodedImage (not an Image) so 
that you have access to the getImageData() method.

Original comment by st...@weblite.ca on 24 Jun 2014 at 2:21