0
我想从java运行scanimage命令。命令成功执行但我无法读取从命令返回的图像。我想从终端读取图像,并通过Java将其转换为base64字符串。我的代码:执行从Java的scanimage命令
public String getimagefromscanner(String device)
{
try {
Process p = Runtime.getRuntime().exec("scanimage --resolution=300 -l 0 -t 0 -y 297 -x 210 --device-name " + device);
BufferedInputStream input = new BufferedInputStream(p.getInputStream());
byte[] file = new byte[input.available()];
input.read(file);
String result = new String(Base64.getDecoder().decode(file));
p.waitFor();
p.destroy();
return result;
} catch (IOException e) {
return e.getLocalizedMessage();
} catch (InterruptedException e) {
return e.getLocalizedMessage();
}
}
的可能的复制(http://stackoverflow.com/questions/8149828/read-the-output-from-java-exec) –
是的,我可以读线作为字符串,但我不知道如何转换为base64。我不知道哪个数据类型返回。它返回'304DNpï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï ¿½ï¿...' – Burak
它不起作用。 – Burak