package com.haier.util.common;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.haier.bean.PolicyBean;
import com.haier.dto.PolicyPersonDto;
import com.haier.dto.PolicyProductDto;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class PictureUtil {
private static void createImage(String fileLocation, BufferedImage image) {
try {
FileOutputStream fos = new FileOutputStream(fileLocation);
BufferedOutputStream bos = new BufferedOutputStream(fos);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(image);
bos.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void graphicsGeneration(String path, PolicyBean policyBean) {
int imageWidth = 1000;// 图片的宽度
int imageHeight = 1000;// 图片的高度
BufferedImage image = new BufferedImage(imageWidth, imageHeight,
BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
graphics.setColor(Color.white);
graphics.fillRect(0, 0, imageWidth, imageHeight);
graphics.setColor(Color.ORANGE);
graphics.setFont(new Font("宋体", Font.BOLD, 20));
PolicyPersonDto policyPersonDto = policyBean.getPolicyPersonDto();
PolicyProductDto policyProductDto = policyBean.getPolicyProductDto();
int num = 50;
graphics.drawString("手机号 : " + policyPersonDto.getMobile(), 50, num);
num += 50;
graphics.drawString("登陆密码 : " + policyPersonDto.getPassword(), 50, num);
num += 50;
graphics.drawString("身份证号 : " + policyPersonDto.getIdentityCard(), 50, num);
num += 50;
graphics.drawString("姓名 : " + policyPersonDto.getUserName(), 50, num);
num += 50;
graphics.drawString("所在地区 : " + policyPersonDto.getArea(), 50, num);
num += 50;
graphics.drawString("常住地址 : " + policyPersonDto.getAddress(), 50, num);
num += 50;
graphics.drawString("微信号 : " + policyPersonDto.getWechatNo(), 50, num);
num += 50;
graphics.drawString("QQ号 : " + policyPersonDto.getQq(), 50, num);
num += 50;
graphics.drawString("Email : " + policyPersonDto.getEmail(), 50, num);
num += 50;
graphics.drawString("品牌 : " + policyProductDto.getBrand(), 50, num);
num += 50;
graphics.drawString("型号 : " + policyProductDto.getModel(), 50, num);
num += 50;
graphics.drawString("商品编号 : " + policyProductDto.getProductId(), 50, num);
num += 50;
graphics.drawString("购买日期 : " + policyProductDto.getPurchaseDate(), 50, num);
num += 50;
graphics.drawString("购买价格 : " + policyProductDto.getPurchasePrice(), 50, num);
num += 50;
graphics.drawString("购买途径 : " + policyProductDto.getPurchaseWay(), 50, num);
num += 50;
graphics.drawString("报修电话 : " + policyProductDto.getWarrantyPhone(), 50, num);
num += 50;
graphics.drawString("延保单位 : " + policyProductDto.getExtendedWarrantyUnit(), 50, num);
num += 50;
graphics.drawString("延保电话 : " + policyProductDto.getExtendedWarrantyPhone(), 50, num);
num += 50;
graphics.drawString("发票编号 : " + policyProductDto.getInvoiceNo(), 50, num);
createImage(path, image);
}
public static void main(String[] args){
List