문제

I have a ByteArrayOutputStream representation of a JPEG image (although I could use GIF or PNG if that would work better). I would like to display this on the form, such as in a label or image object. I am constrained by the fact that I cannot write the image to a file, I can only ever store it in memory.

도움이 되었습니까?

해결책

One of the (easiest) possibilites to solve the problem is creating a ByteArrayInputStream and then passing it to ImageIO:

ByteArrayOutputStream output = new ByteArrayOutputStream();
// save the image to the output stream
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
BufferedImage image = ImageIO.read(input);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top