解决包名冲突问题
This commit is contained in:
parent
bc3e29c2cb
commit
c42c3a2e31
@ -5,11 +5,14 @@ import cn.com.tenlion.buildingpictures.pojo.dtos.picturestemplatearea.PicturesTe
|
||||
import cn.com.tenlion.buildingpictures.service.picturestemplate.IPicturesTemplateService;
|
||||
import cn.com.tenlion.buildingpictures.service.picturestemplatearea.IPicturesTemplateAreaService;
|
||||
import cn.com.tenlion.buildingpictures.service.picturestemplatebuilding.IPicturesTemplateBuildingService;
|
||||
import cn.com.tenlion.buildingpictures.util.BaiDuMapUtil;
|
||||
import cn.com.tenlion.buildingpictures.util.BarCodeUtils;
|
||||
import cn.com.tenlion.buildingpictures.util.CreateImageBean;
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.module.file.service.IFileService;
|
||||
import ink.wgink.pojo.pos.FilePO;
|
||||
import ink.wgink.properties.FileProperties;
|
||||
import ink.wgink.util.QRCodeUtil;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
@ -50,7 +53,13 @@ public class PicturesTemplateBuildingServiceImpl extends DefaultBaseService impl
|
||||
// 创建画布
|
||||
BufferedImage image = new BufferedImage(backWidth, backHeight, Image.SCALE_SMOOTH);
|
||||
// 得到图片操作对象
|
||||
Graphics graphics = image.getGraphics();
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
|
||||
//消除文字锯齿
|
||||
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
//消除图片锯齿
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// 对底图进行裁剪
|
||||
Image backImg = thumbnail(backFile, backWidth + 1, backHeight);
|
||||
// 将底图放入模板中
|
||||
@ -91,16 +100,65 @@ public class PicturesTemplateBuildingServiceImpl extends DefaultBaseService impl
|
||||
// 将头像放入模板中
|
||||
graphics.drawImage(img, bean.getX(), bean.getY(),null);
|
||||
}
|
||||
// 条形码
|
||||
if("3".equals(bean.getType())) {
|
||||
BufferedImage barcode = BarCodeUtils.getBarcode(bean.getContent(), bean.getWidth(), bean.getHeight(), new Color(bean.getColor()[0],bean.getColor()[1],bean.getColor()[2]));
|
||||
// 将条形码放入模板中
|
||||
graphics.drawImage(barcode, bean.getX(), bean.getY(),null);
|
||||
}
|
||||
// 二维码
|
||||
if("4".equals(bean.getType())) {
|
||||
BufferedImage rq = BarCodeUtils.getRQ(bean.getContent(), bean.getWidth(), bean.getHeight(), new Color(bean.getColor()[0],bean.getColor()[1],bean.getColor()[2]));
|
||||
// 将二维码放入模板中
|
||||
graphics.drawImage(rq, bean.getX(), bean.getY(),null);
|
||||
}
|
||||
// 地图坐标
|
||||
if("5".equals(bean.getType())) {
|
||||
BufferedImage map = BaiDuMapUtil.getImage(bean.getContent(), bean.getWidth(), bean.getHeight());
|
||||
// 将地图放入模板中
|
||||
graphics.drawImage(map, bean.getX(), bean.getY(),null);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public List<String> createText(Integer width, Integer fontSize, String content) {
|
||||
char[] c = content.toCharArray();
|
||||
double count = 0;
|
||||
double rowCount = width / fontSize;
|
||||
List<String> contentList = new ArrayList<String>();
|
||||
StringBuffer rowContent = new StringBuffer();
|
||||
for(int i = 0; i < c.length; i ++) {
|
||||
String len = Integer.toBinaryString(c[i]);
|
||||
rowContent.append(c[i]);
|
||||
|
||||
if(len.length() > 8) {
|
||||
count++;
|
||||
}else{
|
||||
count = (count + 0.5);
|
||||
}
|
||||
|
||||
if((count+1) >= rowCount || i == c.length-1 || '\n' == c[i]) {
|
||||
count = 0;
|
||||
contentList.add(rowContent.toString().replace("\n", ""));
|
||||
rowContent.setLength(0);
|
||||
}
|
||||
}
|
||||
return contentList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createImage(List<CreateImageBean> list, File backFile, int backWidth, int backHeight) throws IOException {
|
||||
// 创建画布
|
||||
BufferedImage image = new BufferedImage(backWidth, backHeight, Image.SCALE_SMOOTH);
|
||||
// 得到图片操作对象
|
||||
Graphics graphics = image.getGraphics();
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
|
||||
//消除文字锯齿
|
||||
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
//消除图片锯齿
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// 对底图进行裁剪
|
||||
Image backImg = thumbnail(backFile, backWidth + 1, backHeight);
|
||||
// 将底图放入模板中
|
||||
@ -126,7 +184,15 @@ public class PicturesTemplateBuildingServiceImpl extends DefaultBaseService impl
|
||||
// 左侧
|
||||
}else{
|
||||
// 将文字放入模板中
|
||||
graphics.drawString(bean.getContent(), bean.getX(), ( bean.getY() + ( bean.getHeight() / 2) + ( bean.getFontSize() / 2) ) - 3);
|
||||
List<String> rowList = createText(bean.getWidth(), bean.getFontSize(), bean.getContent());
|
||||
int index = 0;
|
||||
for (String fontContent : rowList) {
|
||||
/**
|
||||
* 对内容进行封装换行
|
||||
*/
|
||||
graphics.drawString(fontContent, bean.getX(), bean.getY() + (bean.getFontSize() * index) + 10);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 图片
|
||||
@ -141,6 +207,24 @@ public class PicturesTemplateBuildingServiceImpl extends DefaultBaseService impl
|
||||
// 将头像放入模板中
|
||||
graphics.drawImage(img, bean.getX(), bean.getY(),null);
|
||||
}
|
||||
// 条形码
|
||||
if("3".equals(bean.getType())) {
|
||||
BufferedImage barcode = BarCodeUtils.getBarcode(bean.getContent(), bean.getWidth(), bean.getHeight(), new Color(bean.getColor()[0],bean.getColor()[1],bean.getColor()[2]));
|
||||
// 将条形码放入模板中
|
||||
graphics.drawImage(barcode, bean.getX(), bean.getY(),null);
|
||||
}
|
||||
// 二维码
|
||||
if("4".equals(bean.getType())) {
|
||||
BufferedImage rq = BarCodeUtils.getRQ(bean.getContent(), bean.getWidth(), bean.getHeight(), new Color(bean.getColor()[0],bean.getColor()[1],bean.getColor()[2]));
|
||||
// 将二维码放入模板中
|
||||
graphics.drawImage(rq, bean.getX(), bean.getY(),null);
|
||||
}
|
||||
// 地图坐标
|
||||
if("5".equals(bean.getType())) {
|
||||
BufferedImage map = BaiDuMapUtil.getImage(bean.getContent(), bean.getWidth(), bean.getHeight());
|
||||
// 将地图放入模板中
|
||||
graphics.drawImage(map, bean.getX(), bean.getY(),null);
|
||||
}
|
||||
}
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ImageIO.write(image, "png", stream);
|
||||
|
@ -0,0 +1,49 @@
|
||||
package cn.com.tenlion.buildingpictures.util;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* 百度地图相关工具类
|
||||
* ClassName: BaiDuMapUtil
|
||||
* @Description: TODO
|
||||
* 创建工具: MyEclipse2014
|
||||
* 运行环境: [Tomcat7以上,MySql5.6以上,JDK7以上]
|
||||
* @author 崔宝铖
|
||||
* @date 2019年6月19日
|
||||
*/
|
||||
public class BaiDuMapUtil {
|
||||
|
||||
/** 百度地图开发Key */
|
||||
private static String ak = "VchhMAkuOzvkaI0NcZSNNippil968u9G";
|
||||
|
||||
public static BufferedImage getImage(String center, Integer width, Integer height) throws IOException {
|
||||
URL url = new URL("http://api.map.baidu.com/staticimage/v2?ak=" + ak + "&width=" + width + "&height=" + ( height + 15) + "¢er=" + center + "&zoom=15©right=1");
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
//设置超时间为5秒
|
||||
conn.setConnectTimeout(5*1000);
|
||||
//防止屏蔽程序抓取而返回403错误
|
||||
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
||||
//得到输入流
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
//获取自己数组
|
||||
byte[] getData = readInputStream(inputStream);
|
||||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(getData));
|
||||
return image.getSubimage(0, 0, width, height);
|
||||
}
|
||||
|
||||
private static byte[] readInputStream(InputStream inputStream) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
int len = 0;
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
while((len = inputStream.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
}
|
||||
bos.close();
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
package cn.com.tenlion.buildingpictures.util;
|
||||
|
||||
import com.google.zxing.*;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import com.google.zxing.qrcode.encoder.QRCode;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* 创建二维码工具类
|
||||
* ClassName: BarCodeUtils
|
||||
* @Description: TODO
|
||||
* 创建工具: MyEclipse2014
|
||||
* 运行环境: [Tomcat7以上,MySql5.6以上,JDK7以上]
|
||||
* @author 崔宝铖
|
||||
* @date 2019年3月1日
|
||||
*/
|
||||
public class BarCodeUtils {
|
||||
|
||||
public static String CODE = "utf-8";
|
||||
public static int SUBCODE = 10; // 取uuid的前10位
|
||||
public static int BLACK = 0xff000000;
|
||||
public static int WHITE = 0xFFFFFFFF;
|
||||
public static int WIDTH = 180;
|
||||
public static int HEIGHT = 100;
|
||||
|
||||
/**
|
||||
* 生成RQ二维码
|
||||
*
|
||||
* @param str 内容
|
||||
* @param height 高度(px)
|
||||
* @author wuhongbo
|
||||
*/
|
||||
public static BufferedImage getRQ(String str, Integer width, Integer height, Color color) {
|
||||
try {
|
||||
/** 定义Map集合封装二维码配置信息 */
|
||||
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
|
||||
/** 设置二维码图片的内容编码 */
|
||||
hints.put(EncodeHintType.CHARACTER_SET, CODE);
|
||||
/** 设置二维码的纠错级别 */
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
|
||||
/** 设置二维码图片的上、下、左、右间隙 */
|
||||
hints.put(EncodeHintType.MARGIN, 0);
|
||||
/**
|
||||
* 创建二维码字节转换对象
|
||||
* 第一个参数:二维码图片中的内容
|
||||
* 第二个参数:二维码格式器
|
||||
* 第三个参数:生成二维码图片的宽度
|
||||
* 第四个参数:生成二维码图片的高度
|
||||
* 第五个参数:生成二维码需要配置信息
|
||||
* */
|
||||
BitMatrix bitMatrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, width, height, hints);
|
||||
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
// 设置背景为透明颜色
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
image = graphics.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);
|
||||
Graphics imageGraphics = image.getGraphics();
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
if(bitMatrix.get(x, y)) {
|
||||
// 自定义颜色
|
||||
imageGraphics.setColor(color);
|
||||
imageGraphics.drawRect ( x, y, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
// return toBufferedImage(bitMatrix);
|
||||
// 输出方式
|
||||
// 网页
|
||||
// ImageIO.write(image, "png", response.getOutputStream());
|
||||
// 文件
|
||||
// ImageIO.write(image, "png", file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成一维码(128)
|
||||
*
|
||||
* @param str
|
||||
* @param width
|
||||
* @param height
|
||||
* @return
|
||||
* @author wuhongbo
|
||||
*/
|
||||
public static BufferedImage getBarcode(String str, Integer width, Integer height, Color color) {
|
||||
try {
|
||||
// 文字编码
|
||||
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
|
||||
hints.put(EncodeHintType.CHARACTER_SET, CODE);
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
|
||||
hints.put(EncodeHintType.MARGIN, 0); // 一维码的大小
|
||||
BitMatrix bitMatrix = new MultiFormatWriter().encode(str, BarcodeFormat.CODE_128, width, height, hints);
|
||||
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
// 设置背景为透明颜色
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
image = graphics.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);
|
||||
Graphics imageGraphics = image.getGraphics();
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
if(bitMatrix.get(x, y)) {
|
||||
// 自定义颜色
|
||||
imageGraphics.setColor(color);
|
||||
imageGraphics.drawRect ( x, y, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换成图片
|
||||
*
|
||||
* @param matrix
|
||||
* @return
|
||||
* @author wuhongbo
|
||||
*/
|
||||
private static BufferedImage toBufferedImage(BitMatrix matrix) {
|
||||
int width = matrix.getWidth();
|
||||
int height = matrix.getHeight();
|
||||
BufferedImage image = new BufferedImage(width, height,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
}
|
@ -62,22 +62,27 @@
|
||||
<input type="radio" name="templateAreaServerLink" lay-filter="templateAreaServerLinkFilter" value="2" title="图片" />
|
||||
<input type="radio" name="templateAreaServerLink" lay-filter="templateAreaServerLinkFilter" value="3" title="条形码" />
|
||||
<input type="radio" name="templateAreaServerLink" lay-filter="templateAreaServerLinkFilter" value="4" title="二维码" />
|
||||
<input type="radio" name="templateAreaServerLink" lay-filter="templateAreaServerLinkFilter" value="5" title="地图位置" />
|
||||
</div>
|
||||
</div>
|
||||
<div id="areaFontValueDiv"></div>
|
||||
<script id="areaFontValueScript" type="text/html">
|
||||
{{# if(d != '2') { }}
|
||||
<div class="layui-form-item layui-row">
|
||||
<div class="layui-form-item layui-row {{ d == 1 ? 'layui-form-text' : ''}}">
|
||||
<div class="layui-col-lg12">
|
||||
<label class="layui-form-label">{{ d == 3 ? '条形码数据' : d == 4 ? '二维码数据' : '示例文字'}}<span style="color: red">*</span></label>
|
||||
<label class="layui-form-label">{{ d == 3 ? '条形码数据' : d == 4 ? '二维码数据' : d == 5 ? '地图位置' : '示例文字'}}<span style="color: red">*</span></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" id="templateAreaFontValue" name="templateAreaFontValue" class="layui-input" value="" placeholder="请输入{{ d == 3 ? '条形码数据' : d == 4 ? '二维码数据' : '文字例值'}}" >
|
||||
{{# if(d == '1') { }}
|
||||
<textarea id="templateAreaFontValue" name="templateAreaFontValue" class="layui-textarea" placeholder="请输入文字例值"></textarea>
|
||||
{{# } else { }}
|
||||
<input type="text" id="templateAreaFontValue" name="templateAreaFontValue" class="layui-input" value="" placeholder="请输入{{ d == 3 ? '条形码数据' : d == 4 ? '二维码数据' : d == 5 ? '坐标或地名' : '文字例值'}}" >
|
||||
{{# } }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-row">
|
||||
<div class="layui-col-lg12">
|
||||
<label class="layui-form-label">{{ d == 3 ? '条形码' : d == 4 ? '二维码' : '文字'}}颜色<span style="color: red">*</span></label>
|
||||
<label class="layui-form-label">{{ d == 3 ? '条形码' : d == 4 ? '二维码' : d == 5 ? '地图' : '文字'}}颜色<span style="color: red">*</span></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" readonly id="templateAreaFontColor" name="templateAreaFontColor" class="layui-input dataInputRowFilter selectColor" value="rgb(0, 0, 0)" placeholder="" >
|
||||
<div id="test-all" style="height:38px;width:5.5%;float:left;background-color:rgb(0, 0, 0)"></div>
|
||||
@ -89,8 +94,9 @@
|
||||
<div class="layui-col-lg12">
|
||||
<label class="layui-form-label">文字字体<span style="color: red">*</span></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="templateAreaFontFamily" checked value="宋体" title="宋体" />
|
||||
<input type="radio" name="templateAreaFontFamily" value="微软雅黑" title="微软雅黑" />
|
||||
<input type="radio" name="templateAreaFontFamily" checked value="黑体" title="黑体" />
|
||||
<input type="radio" name="templateAreaFontFamily" value="宋体" title="宋体" />
|
||||
<input type="radio" name="templateAreaFontFamily" value="楷体" title="楷体" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -68,11 +68,15 @@
|
||||
<div id="areaFontValueDiv"></div>
|
||||
<script id="areaFontValueScript" type="text/html">
|
||||
{{# if(d != '2') { }}
|
||||
<div class="layui-form-item layui-row">
|
||||
<div class="layui-form-item layui-row {{ d == 1 ? 'layui-form-text' : ''}}">
|
||||
<div class="layui-col-lg12">
|
||||
<label class="layui-form-label">{{ d == 3 ? '条形码数据' : d == 4 ? '二维码数据' : '示例文字'}}<span style="color: red">*</span></label>
|
||||
<label class="layui-form-label">{{ d == 3 ? '条形码数据' : d == 4 ? '二维码数据' : d == 5 ? '地图位置' : '示例文字'}}<span style="color: red">*</span></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" id="templateAreaFontValue" name="templateAreaFontValue" class="layui-input" placeholder="请输入{{ d == 3 ? '条形码数据' : d == 4 ? '二维码数据' : '文字例值'}}" >
|
||||
{{# if(d == '1') { }}
|
||||
<textarea id="templateAreaFontValue" name="templateAreaFontValue" class="layui-textarea" placeholder="请输入文字例值"></textarea>
|
||||
{{# } else { }}
|
||||
<input type="text" id="templateAreaFontValue" name="templateAreaFontValue" class="layui-input" value="" placeholder="请输入{{ d == 3 ? '条形码数据' : d == 4 ? '二维码数据' : d == 5 ? '坐标或地名' : '文字例值'}}" >
|
||||
{{# } }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -90,8 +94,9 @@
|
||||
<div class="layui-col-lg12">
|
||||
<label class="layui-form-label">文字字体<span style="color: red">*</span></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="templateAreaFontFamily" value="黑体" title="黑体" />
|
||||
<input type="radio" name="templateAreaFontFamily" value="宋体" title="宋体" />
|
||||
<input type="radio" name="templateAreaFontFamily" value="微软雅黑" title="微软雅黑" />
|
||||
<input type="radio" name="templateAreaFontFamily" value="楷体" title="楷体" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user