0
I found this code on the Internet and made some changes, but I’m not sure what’s going wrong.
Code:
public class main
{
public static void main(String[] args) throws IOException
{
String key = "Lucas Caresia";
BufferedImage bufferedImage = ImageIO.read(new File("recibo.png"));
Graphics graphics = bufferedImage.getGraphics();
graphics.setColor(Color.BLACK);
graphics.setFont(new Font("Arial Black", Font.PLAIN, 15));
graphics.drawString(key, 420, 560);
ImageIO.write(bufferedImage, "png", new File("recibo.jpg"));
System.out.println("Image Created");
}
}
Image before:
Image after (visualized by eclipse):
The second image is not showing
– user28595
Exactly this the problem, I tried with several different image viewers, however it continues not appearing.
– Lucas Caresia
Are you sure the image
recibo.png
exists and it’s about the image you want?– Victor Stafusa
Although you are set to PNG format and saving with extension ". jpg", your code does not seem to have anything wrong. I tested it here and it works "correctly" (it’s just writing the text in the wrong coordinate, but the image generates normally). I will vote as not reproduced.
– Luiz Vieira
Even if I define as PGN it saves as JPG, however I do not define it in the code, I do not know how to solve
– Lucas Caresia