Java-generated transparent background picture (1/2)

Source: Internet
Author: User
Tags save file

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:

Home 1 2 last page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.