my app displays images created using image.createimage(). in cases, images blank, on ios. images work fine on android. also, create several images using image.createimage() , of them work fine. don't see difference between , these.
to reproduce, run enclosed app on both android , ios. app shows 2 images. second 1 taken bottom half of first one. on android, images show fine. on ios, images show few seconds, vanish. turns out show while ios displaying startup screen. once switches actual app, images blank, although take same space. further tests reveal images correct size filled transparent pixels.
i should that, in actual application, images scale size of screen, , colored according user preference, can't load them resource.
(btw notice change made stop method. unrelated worth mentioning.)
here's test case:
import com.codename1.ui.component; import com.codename1.ui.container; import com.codename1.ui.display; import com.codename1.ui.form; import com.codename1.ui.dialog; import com.codename1.ui.graphics; import com.codename1.ui.image; import com.codename1.ui.label; import com.codename1.ui.layouts.borderlayout; import com.codename1.ui.layouts.boxlayout; import com.codename1.ui.plaf.uimanager; import com.codename1.ui.util.resources; import com.codename1.io.log; import com.codename1.ui.toolbar; import java.util.arrays; /** * file generated <a href="https://www.codenameone.com/">codename one</a> purpose * of building native mobile applications using java. */ @suppresswarnings("unused") public class halfimagebug { private form current; private resources theme; public void init(object context) { theme = uimanager.initfirsttheme("/theme"); // enable toolbar on forms default toolbar.setglobaltoolbar(true); } public void start() { if (current != null) { current.show(); return; } form hi = new form("hi world", new borderlayout()); hi.addcomponent(borderlayout.center, makecomponent()); hi.show(); } public void stop() { current = display.getinstance().getcurrent(); // if, should while, in case there multiple layers of dialogs. while (current instanceof dialog) { ((dialog) current).dispose(); current = display.getinstance().getcurrent(); } } public void destroy() { } private component makecomponent() { final container container = new container(new boxlayout(boxlayout.y_axis)); container.setscrollabley(true); container.add(new label("full image:")); image fullicon = createfullimage(0x44ff00, 40, 30); label fullimage = new label(fullicon); container.add(fullimage); container.add(new label("---")); container.add(new label("half image:")); image halficon = createhalfsizeimage(fullicon); label halfimage = new label(halficon); container.add(halfimage); return container; } private image createfullimage(int color, int verticaldiameter, int horizontalradius) { // make sure it's number. otherwise half image have right , left halves reversed! int diameter = (verticaldiameter / 2) * 2; final int iconwidth = 2 * horizontalradius; int imagewidth = iconwidth + 2; int imageht = diameter + 2; image fullimage = image.createimage(imagewidth, imageht); graphics g = fullimage.getgraphics(); g.setantialiased(true); g.setcolor(color); g.fillrect(0, 0, imagewidth, imageht); g.setcolor(darken(color, 25)); g.fillarc(1, 1, iconwidth, diameter, 180, 360); g.setcolor(0xbfbfbf); final int smallerht = (9 * diameter) / 10; g.fillarc(0, 0, iconwidth, smallerht, 180, 360); image maskimage = image.createimage(imagewidth, imageht); g = maskimage.getgraphics(); g.setantialiased(true); g.setcolor(0); g.fillrect(0, 0, imagewidth, imageht); g.setcolor(0xff); g.fillarc(1, 1, iconwidth, diameter, 180, 360); fullimage = fullimage.applymask(maskimage.createmask()); return fullimage; } private image createhalfsizeimage(image fullimage) { int imagewidth = fullimage.getwidth(); int imageht = fullimage.getheight(); int[] rgbvalues = fullimage.getrgb(); // yeah, i've since discovered more sensible way this, doesn't fix bug. int[] bottomhalf = arrays.copyofrange(rgbvalues, rgbvalues.length / 2, rgbvalues.length); //noinspection stringconcatenation log.p("cutting side image " + imagewidth + " x " + imageht + " " + imagewidth + " x " + (imageht / 2)); return image.createimage(bottomhalf, imagewidth, imageht / 2); } private static int darken(int color, int percent) { if ((percent > 100) || (percent < 0)) { throw new illegalargumentexception("percent out of range: " + percent); } int percentremaining = 100 - percent; return (darkenprimary((color & 0xff0000) >> 16, percentremaining) << 16) | (darkenprimary((color & 0xff00) >> 8, percentremaining) << 8) | (darkenprimary(color & 0xff, percentremaining)); } private static int darkenprimary(int primaryvalue, int percentremaining) { if ((primaryvalue < 0) || (primaryvalue > 255)) { throw new illegalargumentexception("primary value out of range (0-255): " + primaryvalue); } return (primaryvalue * percentremaining) / 100; } }
this discussed in this issue.
generally images appear because of screenshot process shows them never show on ios natively.
a common cause these issues creating images off of edt doesn't seem issue in specific code.
it's hard see going on guess we'll need evaluate issue.
Comments
Post a Comment