我的意思是把它作为注释发布在this question,但我没有足够的代表,但我没有看到别的方法,只是提出了一个新问题(尽管看起来有点多余)。从JSF bean传递图像到Applet
无论如何,我试图解决skuntsel写道,但反向:我编码的图像,并从豆到JavaScript方法发送它(我使用ICEfaces的,所以我把它叫做这样JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), functionCall)
)。我在Applet中获得了编码的字符串,但是当我尝试解码它时,没有任何反应,它后面的代码无法访问。
我错过了什么吗?提前致谢!
编辑:这里是我使用的代码。
在豆:(通过点击一个按钮触发方法)
BufferedImage originalImage = acquireImage();
byte[] imageInByte = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageIO.write(originalImage, "png", baos);
baos.flush();
imageInByte = baos.toByteArray();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
String imageAsString = Base64.encodeBase64String(imageInByte);
JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), functionCall);
在Javascript中:
function getEncodedImage(image){
var applet = document.getElementById("Applet");
applet.decodeImage(image);
}
在小程序:
public void decodeImage(String image) {
System.out.println(image); //works
byte[] imageByteArray = Base64.decodeBase64(image);
System.out.println("something"); //doesn't print anything
InputStream is = new ByteArrayInputStream(imageByteArray);
try {
BufferedImage img = ImageIO.read(is);
ImageIO.write(img, "png", new File("D:/image.png"));
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
你的问题还不清楚。扩大上下文并将代码添加到问题中。而且,是的,只需在您提到的答案中恢复逻辑即可。 – skuntsel
添加了代码:) – v30