日期:2014-05-20 浏览次数:20772 次
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);
}
}