日期:2014-05-20 浏览次数:20926 次
private File pressTextToImage(BannerPropertiesDto bannerPropertiesDto) throws IOException {
File img = new File(bannerPropertiesDto.getBackgroundImageFile());
Image src = ImageIO.read(img);
int width = src.getWidth(null);
int height = src.getHeight(null);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.drawImage(src, 0, 0, width, height, null);
g.setColor(bannerPropertiesDto.getFontColor());
g.setFont(new Font(bannerPropertiesDto.getFontStyle(), bannerPropertiesDto.getFontThickness(), bannerPropertiesDto.getFontSize()));
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, bannerPropertiesDto.getFontTransparency()));
g.drawString(bannerPropertiesDto.getPressText(), (width - (getLength(bannerPropertiesDto.getPressText()) * bannerPropertiesDto.getFontSize())) / 2 + bannerPropertiesDto.getCoordinatesX(),
(height - bannerPropertiesDto.getFontSize()) / 2 + bannerPropertiesDto.getCoordinatesY());
g.dispose();
File file = new File(bannerPropertiesDto.getBannerImageFile());
ImageIO.write((BufferedImage) image, "PNG", file);
return file;
}