繁体   English   中英

如何将ImageView转换为InputStream

[英]How to convert a ImageView to InputStream

我有一个包含图像的ImageView ,我需要做一个ImageView的getImage()并将其转换为InputStream 这是我的代码:

try {

    File fileImage = new File(ivImage.getImage());

    InputStream isImage = (InputStream) new FileInputStream(fileImage);

} catch (FileNotFoundException e) {
    e.printStackTrace();
}

有没有办法获取ImageView图像并将其转换为InputStream

谢谢

如果您从图像获取字节并创建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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM