java生成透明背景图片(1/2)
1. 生成png图片
int width = 400;
int height = 300;
// 创建bufferedimage对象
bufferedimage image = new bufferedimage(width, height, bufferedimage.type_int_rgb);
// 获取graphics2d
graphics2d g2d = image.creategraphics();
// 画图
g2d.setcolor(new color(255,0,0));
g2d.setstroke(new basicstroke(1));
g2d.draw
//释放对象
g2d.dispose();
// 保存文件
imageio.write(image, "png", new file("c:/test.png"));
int width = 400;
int height = 300;
// 创建bufferedimage对象
bufferedimage image = new bufferedimage(width, height, bufferedimage.type_int_rgb);
// 获取graphics2d
graphics2d g2d = image.creategraphics();
// 画图
g2d.setcolor(new color(255,0,0));
g2d.setstroke(new basicstroke(1));
g2d.draw
//释放对象
g2d.dispose();
// 保存文件
imageio.write(image, "png", new file("c:/test.png"));
这只是绘制图形的代码,其背景是黑色的,如何才能背景透明呢?继续搜索,没有得到结果,不过搜出以下代码,它只是把自己绘制的图形设置为透明或半透明,背景并不透明,如下:
补充:Jsp教程,Java基础