使用EncodedImage.createFromImage方法

时间:2018-07-03 08:07:04

标签: codenameone

我在JSON buildRequestBody(OutputStream os)方法中的代码中使用以下行将引发EDT违规。请告知是否有使用错误。请参阅附件中的日志。

代码:

if (a.getSign() != null) {
body
+= ",\n           \"SignatureData\": \n"
+ "           {\n"
+ "            \"SignatureImage\": \"" + Base64.encodeNoNewline(EncodedImage.createFromImage(a.getSignature(), false).getImageData()) + "\"\n"
+ "           }\n";
} else {
body += "\n";
}

日志:

at com.codename1.impl.javase.JavaSEPort.checkEDT(JavaSEPort.java:699)
at com.codename1.impl.javase.JavaSEPort.getImageWidth(JavaSEPort.java:4744)
at com.codename1.ui.Image.getWidth(Image.java:690)
at com.codename1.ui.EncodedImage.createFromImage(EncodedImage.java:164)   com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:689)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:282)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
com.codename1.impl.javase.JavaSEPort$EDTViolation: EDT Violation Stack!
at com.codename1.impl.javase.JavaSEPort.checkEDT(JavaSEPort.java:699)
at com.codename1.impl.javase.JavaSEPort.getImageHeight(JavaSEPort.java:4755)
at com.codename1.ui.Image.getHeight(Image.java:704)
at com.codename1.ui.EncodedImage.createFromImage(EncodedImage.java:165)
at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:689)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:282)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

1 个答案:

答案 0 :(得分:0)

EncodedImage出于性能目的而执行了边界EDT违规。 EDT违规代码会发送误报,因为我们不知道两者之间的区别。

这可以,并且不会在设备上引起问题。