Hi


I'm having a problem with images I cannot figure out, hope you can help me 
out…


What I'm trying to do is download and place a png scaling down if necessary 
to fit the screen width.

My assumption: If the height of the image is larger than the height of the 
device, then the image is not rendered on devices but it is on simulator 
with no problem.


The problematic image is 1536x4272 and 1MB.


BUT the same image scaled to 768x2136 and 714KB works fine both on 
simulator and devices, so my assumption might not be right and I'm totally 
lost. Or maybe it's a problem with the image, but then why is it working on 
simulator?


To scale the image I'm setting the background of a Label. As I said The 
code below works on simulator but not on iOS or Android.


    public void start() {
        if(current != null){
            current.show();
            return;
        }
        Form f = new Form(new BoxLayout(BoxLayout.Y_AXIS));  
        f.setScrollableY(true);
        Container loading = new Container(new 
BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE)).add(BorderLayout.CENTER,
 
new InfiniteProgress());
        
Util.downloadImageToFileSystem("https://dl.dropboxusercontent.com/u/47281022/IMGP0.png";,
 
            FileSystemStorage.getInstance().getAppHomePath() + 
FileSystemStorage.getInstance().getFileSystemSeparator() + "IMGP0", 
            new CallbackAdapter(){
                @Override
                public void onSucess(Object value) {
                    Image img = (Image) value;
                    int imgHeightDevice = 
(Display.getInstance().getDisplayWidth() * img.getHeight()) / 
img.getWidth();                            
                    Label l = new Label() {
                        @Override
                        protected Dimension calcPreferredSize() {
                            return new 
Dimension(Display.getInstance().getDisplayWidth(), imgHeightDevice);
                        }                            
                    };                        
                    
l.getAllStyles().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
                    l.getAllStyles().setBgImage(img);
                    f.replace(loading, l, null);
                    f.repaint();
                }
            });
        f.addComponent(loading);
        f.show();                        
        
    }



-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/f1d0a5f3-1e6f-4638-a20a-d284dcbadc97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to