我想弄清楚为什么我在模拟器中会有不同的行为(iPhone,Nexus,Nexus5,.在Android真实设备上使用以下代码(我的目标是在背景图像上绘制文本并在背景图像分辨率中保存整个文本):
请注意,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下面是我调用的在图像上绘制文本的方法
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)上的结果:

这是这个设备(Android4.4)的结果:

我的开发系统以Linux上的Eclipse为特色,代号为One V3-4。
我知道模拟器不能重现特定的情况,但是这里没有什么特别的,不是吗?我能做些什么来使模拟器上的行为反映真实的行为,因为在模拟器中测试要困难得多?
编辑:在将我的每个CN1项目库从114号升级到115号之后(参见https://stackoverflow.com/questions/24993130/how-can-i-update-my-codenameone-plugin-and-handed-to-the-latest-classes-update),我现在能够在模拟器和设备中获得相同的行为!伟大的错误修复工作CN1团队!请注意:在我的例子(Eclipse )中,我必须升级中的项目库,每个代码都命名一个项目。
任何帮助都将不胜感激!
干杯,
发布于 2016-06-24 04:31:18
这是一个非常烦人的错误,我们刚刚修好了,以便它可以进入今天的发行版。
只有在仿真器处于缩放模式的情况下,只有在绘制可变图像时才会出现此问题,这两种情况我们都不经常这样做,因为缩放模式不太准确,而可变图像通常比较慢。
谢谢你跟得上这个。
https://stackoverflow.com/questions/37986722
复制相似问题