I have two independant pieces of code that I need to work together, one written by myself and one that is from another project. I essentially have one part of the project that is creating a buffered image. Here is a snippet from it:
BufferedImage screenshot = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
In the other piece of software, it accepts an image file to then pass on as JSON/POST data for another service. Here is it accepting a file:
try(InputStream file = new FileInputStream("temp.png")) {
sendFile(out, "file", file, "temp.png");
}
I don't have much experience working with Images in Java, my current solution is to have the first program write the BufferedImage to a file like this:
File tempFile = new File("/", "temp.png");
ImageIO.write(screenshot, "PNG", tempFile);
Then the second piece of code is able to deal with it properly. The problem arises from it needing to delete the temp file and the issues of arising from that. Is there any way to simplify this? Thanks in advance.