1:获取数据放map之后,调用WaterImage
if (recordMap != null) { WaterImage waterImage = new WaterImage(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(waterImage.createImage(recordMap), "jpg", out); } catch (IOException e) { e.printStackTrace(); } return out.toByteArray(); }2:createImage方法
package com.rjcloud.util;
import com.rjcloud.api.entity.*;
import gui.ava.html.image.generator.HtmlImageGenerator;
import org.apache.commons.collections.map.HashedMap;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Map;
public class WaterImage {
private int imgWidth = 200;
private int imgHeight = 20;
private int size = 14;
public void setImgHeight(int imgHeight) {
this.imgHeight = imgHeight;
}
public int getImgWidth() {
return this.imgWidth;
}
public void setImgWidth(int imgWidth) {
this.imgWidth = imgWidth;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
String getShowStr(String str){
return str==null?"":str;
}
public BufferedImage createImage(Object obj) {
HtmlImageGenerator imageGenerator = new HtmlImageGenerator();
StringBuffer stringBuffer=new StringBuffer();
//把值放在html里面
Map map= (Map) obj;
// stringBuffer.append("
"+entity.getCf_cfmc()+"
");
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
stringBuffer.append(
" " +
"" +
"" +
"" +
" " +
" "+""+"" +
" " +
" " +
" " +
" " );
int i=1;
for(Object key2 : map.keySet()){
if(i%2!=0&&i!=map.keySet().size()) {
stringBuffer.append("" + key2 + " " +
"" + map.get(key2) + " ");
}else if(i%2!=0&&i==map.keySet().size()){
stringBuffer.append("" + key2 + " " +
"" + map.get(key2) + " ");
}else{
stringBuffer.append("" + key2 + " " +
"" + map.get(key2) + " ");
}
i++;
}
stringBuffer.append("
" +
" " +
" " +
"" +
"" +
"" +
" " +
"
"); // stringBuffer.append("