[英]How to convert a ImageView to InputStream
I have an ImageView
that contains an image, what I need is to make a getImage() of the ImageView
and convert it to an InputStream
. 我有一个包含图像的
ImageView
,我需要做一个ImageView
的getImage()并将其转换为InputStream
。 This is the code that I have: 这是我的代码:
try {
File fileImage = new File(ivImage.getImage());
InputStream isImage = (InputStream) new FileInputStream(fileImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Is there a way to get the ImageView
image and convert it to InputStream
? 有没有办法获取
ImageView
图像并将其转换为InputStream
?
Thanks 谢谢
What if you get bytes from an image and create ByteArrayInputStream? 如果您从图像获取字节并创建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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.