1. Generate PNG picture
int width = 400;
int height = 300;
Creating BufferedImage Objects
BufferedImage image = new BufferedImage (width, height, bufferedimage.type_int_rgb);
Get graphics2d
Graphics2D g2d = Image.creategraphics ();
Drawing
G2d.setcolor (new color (255,0,0));
G2d.setstroke (New Basicstroke (1));
G2d.draw
Releasing objects
G2d.dispose ();
Save File
Imageio.write (Image, "PNG", New File ("C:/test.png"));
int width = 400;
int height = 300;
Creating BufferedImage Objects
BufferedImage image = new BufferedImage (width, height, bufferedimage.type_int_rgb);
Get graphics2d
Graphics2D g2d = Image.creategraphics ();
Drawing
G2d.setcolor (new color (255,0,0));
G2d.setstroke (New Basicstroke (1));
G2d.draw
Releasing objects
G2d.dispose ();
Save File
Imageio.write (Image, "PNG", New File ("C:/test.png"));
This is just a drawing of the code, its background is black, how can the background transparent? Continue the search, did not get results, but the following code is found, it simply sets its own drawing of the figure is transparent or translucent, the background is not transparent, as follows: