【发布时间】:2016-10-25 11:58:10
【问题描述】:
我试图弄清楚为什么我在模拟器(iPhone、Nexus、Nexus5、... skins)VS 上使用以下代码在 Android 真实设备上得到不同的行为(我的目标是在背景图像并以背景图像分辨率保存整体):
请注意,GUI 是由 Designer 完成的。
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
这是我调用的在图像上绘制文本的方法
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
我的开发系统在 Linux 上使用代号 One V3-4 的 Eclipse。
我知道模拟器无法重现特定情况,但这里没有什么特别的不是吗?我该怎么做才能使模拟器上的行为反映真实行为,因为在模拟器中测试会更方便?
编辑:在将我的每个 CN1 项目库从版本 114 升级到 115 后(请参阅 this question for details on how to do the upgrade),我现在能够在模拟器和设备中获得相同的行为!伟大的错误修复工作 CN1 团队! 请注意:在我的情况下(Eclipse - Linux),我必须升级 每个 Codename One 项目中的项目库。
任何帮助将不胜感激!
干杯,
【问题讨论】:
标签: drawing codenameone simulator