为什么我在Codename One模拟器中的行为与在真正的Android设备上有所不同? [英] Why do I get a different behviour in Codename One simulator than on a real Android device?

查看:123
本文介绍了为什么我在Codename One模拟器中的行为与在真正的Android设备上有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用以下代码找出为什么在Android真实设备上的模拟器(iPhone,Nexus,Nexus5,...皮肤)VS中出现不同的行为(我的目标是在背景图像,并以背景图像分辨率保存整个图像):

I am trying to figure out why I get a different behaviour in the simulator (iPhone, Nexus, Nexus5, ... skins ) VS on an Android real device with the following code (my goal is to draw a text over a background image and save the whole in background image resolution) :

请注意,GUI是使用设计器完成的。

    protected void beforeMain(Form f) {

    // The drawing label will contain the whole photo montage
    f.setLayout(new LayeredLayout());
    final Label drawing = new Label();
    f.addComponent(drawing);

    String nom = "Hello World";

    // Image mutable dans laquelle on va dessiner (fond blancpar défaut)
    // synthe is an Image
    Image mutableImage = Image.createImage(synthe.getWidth(), synthe.getHeight());
    drawing.getUnselectedStyle().setBgImage(mutableImage);
    drawing.getUnselectedStyle().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);

    // Draws over the background image and put all together on the mutable image.
    paintSyntheOnBackground(mutableImage.getGraphics(), 
            synthe,
            nom,
            synthe.getWidth(), 
            synthe.getHeight());

    long time = new Date().getTime();
    OutputStream os;
    try {
        os = Storage.getInstance().createOutputStream("screenshot_" + Long.toString(time) + ".png");
        ImageIO.getImageIO().save(mutableImage, os, ImageIO.FORMAT_PNG, 1.0f);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

} // end of beforeMain

是我用来在图像上绘制文本的方法

And here is the method I call to draw a text over an image

public void paintSyntheOnBackground(Graphics g, 
        Image synthe,
        final String pNom,
        int width, int height) {

     Font myFont = g.getFont();
        g.setFont(myFont);
        int w = myFont.stringWidth(pNom);
        int h = myFont.getHeight();

        // Added just to see the background
        g.setColor(0x0000FF);
        g.fillRect(0, 0, width, height);

        g.setColor(0xff0000);
        int x = g.getTranslateX() + width / 2 - w / 2;
        int y = g.getTranslateY() + height / 2 - h / 2;

        g.drawRect(x, y, w, h);
        g.drawString(pNom, x, y);

} // end of paintSyntheOnBackground

这是模拟器上的结果(GoogleNexus7):

Here is the outcome on the simulator (GoogleNexus7) :

这是设备上的结果(Android 4.4) :

And here is the outcome on the device (Android 4.4) :

我的开发系统在Linux上使用Eclipse,其代号为One V3-4。

My development system features Eclipse on Linux with Codename One V3-4.

我知道模拟器无法重现特定情况,但是这里没有什么特别的地方吗?我该怎么做才能使模拟器上的行为反映真实行为,因为在模拟器中进行测试会更加方便?

I know the simulator cannot reproduce specific case, but here there is nothing special isn't it ? What can I do to make the behaviour on the simulator reflect the real behaviour since it would be much handier to test in the simulator ?

编辑:升级每个我的CN1项目库的版本从114到115(请参阅此问题以获取有关如何进行升级的详细信息),现在我可以在模拟器和设备上获得相同的行为! CN1团队修复错误的工具!
请注意:就我而言(Eclipse-Linux),我必须升级每个代号一个项目中的项目库。

EDIT : After upgrading each of my CN1 project libs from version 114 to 115 (see this question for details on how to do the upgrade), I am now able to get the same behaviour in both simulator and device! Great bug fixing job CN1 team! Please note : In my case (Eclipse - Linux) I had to upgrade the project libs in each and every Codename One project.

任何帮助将不胜感激!

干杯,

推荐答案

这是一个非常令人讨厌的错误,我们现在已解决

This was a really annoying bug that we just fixed now so it can make it to today's release.

仅在模拟器处于缩放模式的情况下绘制可变图像时才会出现此问题,而我们都不经常这样做

The problem only occurs when drawing on a mutable image in a case where the simulator is in scale mode both of which we don't do often as scale mode is less accurate and mutable images are generally slower.

感谢您对此进行跟踪。

这篇关于为什么我在Codename One模拟器中的行为与在真正的Android设备上有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆