Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoban3.0
haoban-manage3.0
Commits
fc8d5933
Commit
fc8d5933
authored
Mar 16, 2023
by
songyinghui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 图片合并居中
parent
5a026396
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
33 deletions
+47
-33
DrawImageUtils.java
...va/com/gic/haoban/manage/service/util/DrawImageUtils.java
+41
-29
month_bkg.png
...manage3-service/src/main/resources/template/month_bkg.png
+0
-0
week_bkg.png
...-manage3-service/src/main/resources/template/week_bkg.png
+0
-0
NotityTest.java
haoban-manage3-service/src/test/java/NotityTest.java
+6
-4
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/util/DrawImageUtils.java
View file @
fc8d5933
package
com
.
gic
.
haoban
.
manage
.
service
.
util
;
package
com
.
gic
.
haoban
.
manage
.
service
.
util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.BufferedImage
;
...
@@ -17,40 +20,49 @@ import java.io.InputStream;
...
@@ -17,40 +20,49 @@ import java.io.InputStream;
**/
**/
public
class
DrawImageUtils
{
public
class
DrawImageUtils
{
public
static
void
drawImage
()
throws
IOException
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
DrawImageUtils
.
class
);
// ImageIcon imageIcon = new ImageIcon("");
//
// URL url = new URL("http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png");
long
startTime
=
System
.
currentTimeMillis
();
InputStream
inputStream
=
DrawImageUtils
.
class
.
getClassLoader
().
getResourceAsStream
(
"template/base_pic.png"
);
if
(
inputStream
==
null
){
return
;
}
BufferedImage
image
=
ImageIO
.
read
(
inputStream
);;
System
.
out
.
println
(
"图片宽度:"
+
image
.
getWidth
()
+
" px"
);
System
.
out
.
println
(
"图片高度:"
+
image
.
getHeight
()
+
" px"
);
Graphics2D
pen
=
image
.
createGraphics
();
pen
.
setColor
(
Color
.
BLACK
);
//pen.setColor(new Color(179, 250, 233, 100));
//Font.PLAIN(正常),Font.BOLD(粗体),Font.ITALIC(斜体)
pen
.
setFont
(
new
Font
(
"微软雅黑"
,
Font
.
ITALIC
,
20
));
pen
.
drawString
(
"我是图片水印"
,
image
.
getWidth
()/
2
,
image
.
getHeight
()/
2
);
/**
pen
.
dispose
();
* 绘画素材月报海报图
* @param fileName
* @param materialNum
* @param amountText
* @throws IOException
*/
public
static
void
drawImageMonth
(
String
fileName
,
String
materialNum
,
String
amountText
)
{
try
{
long
startTime
=
System
.
currentTimeMillis
();
InputStream
inputStream
=
DrawImageUtils
.
class
.
getClassLoader
().
getResourceAsStream
(
"template/month_bkg.png"
);
if
(
inputStream
==
null
)
{
return
;
}
File
file
=
new
File
(
"test2.png"
);
BufferedImage
image
=
ImageIO
.
read
(
inputStream
);
FileOutputStream
fos
=
new
FileOutputStream
(
file
);
Graphics2D
pen
=
image
.
createGraphics
(
);
ImageIO
.
write
(
image
,
"png"
,
fos
);
pen
.
setRenderingHint
(
RenderingHints
.
KEY_TEXT_ANTIALIASING
,
RenderingHints
.
VALUE_TEXT_ANTIALIAS_ON
);
long
endTime
=
System
.
currentTimeMillis
();
pen
.
setColor
(
Color
.
WHITE
);
System
.
out
.
println
(
endTime
-
startTime
);
Font
font
=
new
Font
(
"微软雅黑"
,
Font
.
BOLD
,
56
);
pen
.
setFont
(
font
);
FontMetrics
metrics
=
pen
.
getFontMetrics
(
font
);
int
startX
=
40
+
(
260
-
metrics
.
stringWidth
(
materialNum
))
/
2
;
pen
.
drawString
(
materialNum
,
startX
,
250
);
int
amountX
=
320
+
(
353
-
metrics
.
stringWidth
(
amountText
))
/
2
;
pen
.
drawString
(
amountText
,
amountX
,
250
);
File
file
=
new
File
(
fileName
);
FileOutputStream
fos
=
new
FileOutputStream
(
file
);
ImageIO
.
write
(
image
,
"png"
,
fos
);
pen
.
dispose
();
long
endTime
=
System
.
currentTimeMillis
();
log
.
info
(
"合成图片耗时 {} ms"
,
(
endTime
-
startTime
));
}
catch
(
Exception
ex
){
log
.
info
(
"合成月报图片异常"
,
ex
);
}
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
DrawImageUtils
.
drawImage
();
DrawImageUtils
.
drawImageMonth
(
"test2.png"
,
"104"
,
"13,433.33"
);
DrawImageUtils
.
drawImageMonth
(
"test3.png"
,
"1"
,
"1.43万"
);
}
}
}
}
haoban-manage3-service/src/main/resources/template/month_bkg.png
0 → 100644
View file @
fc8d5933
353 KB
haoban-manage3-service/src/main/resources/template/week_bkg.png
0 → 100644
View file @
fc8d5933
394 KB
haoban-manage3-service/src/test/java/NotityTest.java
View file @
fc8d5933
...
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -109,11 +110,12 @@ public class NotityTest {
...
@@ -109,11 +110,12 @@ public class NotityTest {
messageDTO
.
setUserIds
(
Collections
.
singletonList
(
"wo59NLDQAA2fEL1xL51lJIy9y2N2aulA"
));
messageDTO
.
setUserIds
(
Collections
.
singletonList
(
"wo59NLDQAA2fEL1xL51lJIy9y2N2aulA"
));
QywxNewsArticleMessageDTO
articleInfo
=
new
QywxNewsArticleMessageDTO
();
QywxNewsArticleMessageDTO
articleInfo
=
new
QywxNewsArticleMessageDTO
();
articleInfo
.
setAppid
(
config
.
getAppid
());
articleInfo
.
setAppid
(
config
.
getAppid
());
articleInfo
.
setTitle
(
"
测试图文标题
"
);
articleInfo
.
setTitle
(
"
素材使用月报
"
);
articleInfo
.
setDescription
(
"
这是一个图文描述
"
);
articleInfo
.
setDescription
(
"
3月1日~3月31日的素材使用月报已生成,请查收
"
);
articleInfo
.
setPagepath
(
"/monthList"
);
articleInfo
.
setPagepath
(
"/monthList"
);
articleInfo
.
setPicurl
(
"https://platform-1251519181.cos.ap-shanghai.myqcloud.com/image/jhdm/enterprise_common-9292fc686bbf4da2a168d4428363e630.jpeg"
);
articleInfo
.
setPicurl
(
"https://platform-1251519181.cos.ap-shanghai.myqcloud.com/image/newdmwltest/enterprise_common-e1e8b3d46fdb4486ad545aae6cba67a1.png"
);
messageDTO
.
setArticleMessages
(
Collections
.
singletonList
(
articleInfo
));
messageDTO
.
setArticleMessages
(
Arrays
.
asList
(
articleInfo
));
boolean
b
=
qywxSuiteApiService
.
sendMessage
(
corpid
,
config
.
getWxSuiteid
(),
messageDTO
);
boolean
b
=
qywxSuiteApiService
.
sendMessage
(
corpid
,
config
.
getWxSuiteid
(),
messageDTO
);
System
.
out
.
println
(
b
);
System
.
out
.
println
(
b
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment