I want to generate a random string and then I need to convert it into an image. I want to store this image in my resource folder of spring.
@Service
public class CapchaServiceImpl implements CapchaService{
@Override
public void CapchaString() {
String capchaString = UUID.randomUUID().toString();
ByteArrayInputStream bais = new ByteArrayInputStream(capchaString.getBytes());
try {
BufferedImage bi=ImageIO.read(bais);
File outputfile = new File("/resources/saved.png");
ImageIO.write(bi, "png", outputfile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
However, when I used this, I am getting java.lang.IllegalArgumentException: image == null!
Exception. Why and what do I need to do?