使用java生成了一张透明的png图片,然后将文字打到图片上,图片就变成一坨黑色了,不透明了,请问有没有人给点建议啊 public static void textMark(String imgPath, String text, Font font,
Color color, int x, int y, float alpha) {
try {
Font Dfont = (font == null) ? new Font("宋体", 20, 13) : font; Image img = ImageIO.read(new File(imgPath)); BufferedImage image = new BufferedImage(img.getWidth(null), img
.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics(); g.drawImage(img, 0, 0, null);
g.setColor(color);
g.setFont(Dfont);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,
alpha));
g.drawString(text, x, y);
g.dispose();
FileOutputStream out = new FileOutputStream(imgPath);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
} catch (Exception e) {
System.out.println(e);
}
}
Color color, int x, int y, float alpha) {
try {
Font Dfont = (font == null) ? new Font("宋体", 20, 13) : font; Image img = ImageIO.read(new File(imgPath)); BufferedImage image = new BufferedImage(img.getWidth(null), img
.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics(); g.drawImage(img, 0, 0, null);
g.setColor(color);
g.setFont(Dfont);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,
alpha));
g.drawString(text, x, y);
g.dispose();
FileOutputStream out = new FileOutputStream(imgPath);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
} catch (Exception e) {
System.out.println(e);
}
}
解决方案 »
- log4j如何 输出异常信息 和 所谓的错误信息 到 指定文件中
- netbeans如何使用图片做界面背景
- 看看这个字符串如何写正则表达式?
- Java中如何用正则表达式匹配 * ? + { } [ ] ( ) 等特殊字符
- java一个很奇怪的问题!
- 导出oracle出错java.lang.OutOfMemoryError: Java heap space
- 求助!关于JButton批量增加的问题,急!!!
- 如果你認為你還算是人的話,你就看一下吧!
- javajavajava?????????
- 征求正确答案,
- 想学习java se请教低级问题
- import org.apache.lucene.analysis.cn.*这个包在哪下,怎么导入
JPG格式不支持透明.