【发布时间】:2017-10-07 10:51:56
【问题描述】:
我正在尝试从 java 运行 scanimage 命令。命令已成功执行,但我无法读取从命令返回的图像。我想从终端读取图像并通过 Java 将其转换为 base64 字符串。我的代码:
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();
}
}
【问题讨论】:
-
是的,我可以将行读取为字符串,但我不知道如何转换为 base64。我不知道返回哪种数据类型。它返回
304DNpï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿ ... -
它不起作用。