|
@@ -24,53 +24,51 @@ public class LogoConfig {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
* @author Administrator sangwenhao
|
|
* @author Administrator sangwenhao
|
|
*/
|
|
*/
|
|
- public BufferedImage LogoMatrix(BufferedImage matrixImage, String logoPath) throws IOException{
|
|
|
|
|
|
+ public BufferedImage LogoMatrix(BufferedImage matrixImage, boolean logo, String logoPath) throws IOException{
|
|
/**
|
|
/**
|
|
* 读取二维码图片,并构建绘图对象
|
|
* 读取二维码图片,并构建绘图对象
|
|
*/
|
|
*/
|
|
- Graphics2D g2 = matrixImage.createGraphics();
|
|
|
|
-
|
|
|
|
- int matrixWidth = matrixImage.getWidth();
|
|
|
|
- int matrixHeigh = matrixImage.getHeight();
|
|
|
|
- File file = null;
|
|
|
|
- BufferedImage logo = null;
|
|
|
|
- try {
|
|
|
|
- /**
|
|
|
|
- * 读取Logo图片
|
|
|
|
- */
|
|
|
|
- if(StrUtil.isEmpty(logoPath)){
|
|
|
|
- ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
|
|
|
- Resource[] resources = resolver.getResources("static/img/logo.jpg");
|
|
|
|
- Resource resource = resources[0];
|
|
|
|
- //获得文件流,因为在jar文件中,不能直接通过文件资源路径拿到文件,但是可以在jar包中拿到文件流
|
|
|
|
- InputStream inputStream = resource.getInputStream();
|
|
|
|
- logo = ImageIO.read(inputStream);
|
|
|
|
- }else {
|
|
|
|
- file = new File(logoPath);
|
|
|
|
- logo = ImageIO.read(file);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ Graphics2D g2 = matrixImage.createGraphics();
|
|
|
|
|
|
|
|
+ if(logo){
|
|
|
|
+ int matrixWidth = matrixImage.getWidth();
|
|
|
|
+ int matrixHeigh = matrixImage.getHeight();
|
|
|
|
+ File file = null;
|
|
|
|
+ BufferedImage logoBuffer = null;
|
|
|
|
+ try {
|
|
|
|
+ /**
|
|
|
|
+ * 读取Logo图片
|
|
|
|
+ */
|
|
|
|
+ if(StrUtil.isEmpty(logoPath)){
|
|
|
|
+ ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
|
|
|
+ Resource[] resources = resolver.getResources("static/img/logo.jpg");
|
|
|
|
+ Resource resource = resources[0];
|
|
|
|
+ //获得文件流,因为在jar文件中,不能直接通过文件资源路径拿到文件,但是可以在jar包中拿到文件流
|
|
|
|
+ InputStream inputStream = resource.getInputStream();
|
|
|
|
+ logoBuffer = ImageIO.read(inputStream);
|
|
|
|
+ }else {
|
|
|
|
+ file = new File(logoPath);
|
|
|
|
+ logoBuffer = ImageIO.read(file);
|
|
|
|
+ }
|
|
|
|
+ }catch (IOException e){
|
|
|
|
+ log.info("读取图片流失败,path="+ logoPath, e);
|
|
|
|
+ }
|
|
|
|
|
|
- }catch (IOException e){
|
|
|
|
- log.info("读取图片流失败,path="+ logoPath, e);
|
|
|
|
|
|
+ //开始绘制图片
|
|
|
|
+ g2.drawImage(logoBuffer,matrixWidth/5*2,matrixHeigh/5*2, matrixWidth/5, matrixHeigh/5, null);//绘制
|
|
|
|
+ BasicStroke stroke = new BasicStroke(5,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
|
|
|
|
+ g2.setStroke(stroke);// 设置笔画对象 44
|
|
|
|
+ //指定弧度的圆角矩形
|
|
|
|
+ RoundRectangle2D.Float round = new RoundRectangle2D.Float(matrixWidth/5*2, matrixHeigh/5*2, matrixWidth/5, matrixHeigh/5,20,20);
|
|
|
|
+ g2.setColor(Color.white);
|
|
|
|
+ g2.draw(round);// 绘制圆弧矩形
|
|
|
|
+ //设置logo 有一道灰色边框
|
|
|
|
+ BasicStroke stroke2 = new BasicStroke(1,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
|
|
|
|
+ g2.setStroke(stroke2);// 设置笔画对象
|
|
|
|
+ RoundRectangle2D.Float round2 = new RoundRectangle2D.Float(matrixWidth/5*2+2, matrixHeigh/5*2+2, matrixWidth/5-4, matrixHeigh/5-4,20,20);
|
|
|
|
+ g2.setColor(new Color(128,128,128));
|
|
|
|
+ g2.draw(round2);// 绘制圆弧矩形
|
|
}
|
|
}
|
|
-
|
|
|
|
- //开始绘制图片
|
|
|
|
- g2.drawImage(logo,matrixWidth/5*2,matrixHeigh/5*2, matrixWidth/5, matrixHeigh/5, null);//绘制
|
|
|
|
- BasicStroke stroke = new BasicStroke(5,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
|
|
|
|
- g2.setStroke(stroke);// 设置笔画对象
|
|
|
|
- //指定弧度的圆角矩形
|
|
|
|
- RoundRectangle2D.Float round = new RoundRectangle2D.Float(matrixWidth/5*2, matrixHeigh/5*2, matrixWidth/5, matrixHeigh/5,20,20);
|
|
|
|
- g2.setColor(Color.white);
|
|
|
|
- g2.draw(round);// 绘制圆弧矩形
|
|
|
|
-
|
|
|
|
- //设置logo 有一道灰色边框
|
|
|
|
- BasicStroke stroke2 = new BasicStroke(1,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
|
|
|
|
- g2.setStroke(stroke2);// 设置笔画对象
|
|
|
|
- RoundRectangle2D.Float round2 = new RoundRectangle2D.Float(matrixWidth/5*2+2, matrixHeigh/5*2+2, matrixWidth/5-4, matrixHeigh/5-4,20,20);
|
|
|
|
- g2.setColor(new Color(128,128,128));
|
|
|
|
- g2.draw(round2);// 绘制圆弧矩形
|
|
|
|
|
|
|
|
g2.dispose();
|
|
g2.dispose();
|
|
matrixImage.flush() ;
|
|
matrixImage.flush() ;
|