2016-06-23 6 views
2

다음 코드로 안드로이드 실제 장치에서 시뮬레이터 (iPhone, Nexus, Nexus5, ... 스킨)에서 다른 동작을 얻는 이유를 알아 내려고합니다. 내 목표는 배경 위에 텍스트를 그리는 것입니다. 이미지를 저장하고 배경 이미지 해상도로 전체 저장) :실제 Android 기기보다 Codename One 시뮬레이터에서 다른 동작이 나타나는 이유는 무엇입니까?

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)에 대한 결과입니다 : outcome on the simulator (GoogleNexus7)

을 그리고 여기에있다 기기의 결과 (Android 4.4) : outcome on the device (Android 4.4)

내 개발 ent 시스템은 Codename One V3-4가 설치된 Linux에서 Eclipse를 제공합니다.

시뮬레이터가 특정 케이스를 재현 할 수 없다는 것을 알고 있지만 여기에는 특별한 것이 없습니다. 시뮬레이터의 동작을 훨씬 더 쉽게 할 수 있기 때문에 시뮬레이터의 동작을 반영하기 위해 내가 할 수있는 일은 무엇입니까?

편집 : 각 CN1 프로젝트 라이브러리를 버전 114에서 115로 업그레이드 한 후 (this question for details on how to do the upgrade 참조) 이제 시뮬레이터와 장치에서 동일한 동작을 얻을 수 있습니다! CN1 팀을 해결하는 위대한 버그! 참고 : 필자의 경우 (Eclipse - Linux) 프로젝트 라이브러리를 각각 으로 업그레이드해야하고 각 코드 명 하나의 프로젝트를 업그레이드해야했습니다.

도움이 될 것입니다.

건배,

답변

1

이것은 우리가 just fixed now 그래서 오늘의 릴리스를 만들 수있는 정말 짜증나는 버그이었다.

시뮬레이터가 스케일 모드에있는 경우 가변 이미지를 그릴 때만 문제가 발생합니다. 스케일 모드가 덜 정확하고 변경 가능한 이미지가 일반적으로 느리기 때문에 자주하지 않습니다.

감사합니다.

+0

당신은 정말로 Codename One Team을 락킹합니다! 이 버그를 수정하면 내 인생을 얼마나 쉽게 만들어 낼 수 있는지 상상할 수 없습니다! 버전 115로 업데이트되었고 현재 예상대로 작동합니다. 너무 많은 @Shai 감사합니다! – HelloWorld

+0

이 문제를 해결해 주셔서 감사합니다 ;-) –

+0

고마워요. 나는 같은 문제를 겪고 있었다. 실제 장치에서 제대로 작동 했으므로 무시하기로 결정했으나이 문제가 해결되는 것이 분명 도움이되었습니다. – MiguelMunoz