在哪里保存图像代号为一个应用程序

时间:2015-01-02 12:57:04

标签: codenameone

我已经用代号1(手动模板)创建了一个页面。我可以在一个应用程序模拟器中看到图像但是当我在我的Android手机上安装它时它会在图像代码上给出java.lang.exception。这是我的代码:

表格firstPage = new Form();         尝试         {             。firstPage.getStyle()setBgImage(Image.createImage( “SRC / COM / ACISM /图像/ low_poly_background.jpg”));         } catch(IOException ex){         }

    firstPage.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;

    Label logoLabel = null;
    try {
        logoLabel = new Label(Image.createImage("src/com/acism/images/logo.png"));
    } catch (IOException ex) {
    }
    logoLabel.getStyle().setBgTransparency(0);
    c.fill = GridBagConstraints.CENTER;
    c.gridy = 0;
    c.gridx = 0;
    firstPage.addComponent(c, logoLabel);

    Label name = new Label("Communication Is Important!");
    name.getUnselectedStyle().setFgColor(0xFFFFFF);
    name.getStyle().setBgTransparency(0);
    c.fill = GridBagConstraints.CENTER;
    c.gridy = 1;
    c.gridx = 0;
    firstPage.addComponent(c, name);

    Button btn = new Button("Get Started");
    btn.getUnselectedStyle().setBgColor(0x3083FF, true);
    btn.getUnselectedStyle().setFgColor(0xFFFFFF);
    c.fill = GridBagConstraints.CENTER;
    c.gridy = 4;
    c.gridx = 0;
    btn.addActionListener(startedListener);
    firstPage.addComponent(c, btn);

    firstPage.show();

注意:shai,图像存储在不同的包中。提前谢谢!

1 个答案:

答案 0 :(得分:0)

图像只能放在src目录的根目录中,所以如果logo.png就在那里,那就像:

Image.createImage("/logo.png")

会工作吗?但是,你不应该这样做!

相反,您应该将图像放在res文件中multi-images,这意味着它们将动态适应设备的DPI。