我有ImageView
包含图片,我需要的是制作ImageView
的getImage()并将其转换为InputStream
。这是我的代码:
try {
File fileImage = new File(ivImage.getImage());
InputStream isImage = (InputStream) new FileInputStream(fileImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
有没有办法获取ImageView
图片并将其转换为InputStream
?
由于
答案 0 :(得分:3)
如果从图像中获取字节并创建ByteArrayInputStream会怎样?
ImageView view = new ImageView();
BufferedImage bImage = SwingFXUtils.fromFXImage(view.getImage(), null);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
ImageIO.write(bImage, "png", outputStream);
byte[] res = outputStream.toByteArray();
InputStream inputStream = new ByteArrayInputStream(res);
} catch (IOException e) {
e.printStackTrace();
}