Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
0881acf4
Commit
0881acf4
authored
Jul 29, 2018
by
Menethil
Browse files
修改默认字体
parent
264c50e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/CreateShareImageTest.java
0 → 100644
View file @
0881acf4
package
org.linlinjava.litemall.admin
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.linlinjava.litemall.core.qcode.QCodeService
;
import
org.linlinjava.litemall.db.domain.LitemallGoods
;
import
org.linlinjava.litemall.db.service.LitemallGoodsService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
@WebAppConfiguration
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
CreateShareImageTest
{
@Autowired
QCodeService
qCodeService
;
@Autowired
LitemallGoodsService
litemallGoodsService
;
@Test
public
void
test
()
{
LitemallGoods
good
=
litemallGoodsService
.
findById
(
1181010
);
qCodeService
.
createGoodShareImage
(
good
.
getId
().
toString
(),
good
.
getPicUrl
(),
good
.
getName
());
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeService.java
View file @
0881acf4
...
...
@@ -46,6 +46,8 @@ public class QCodeService {
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
FontFormatException
e
)
{
e
.
printStackTrace
();
}
}
...
...
@@ -66,7 +68,7 @@ public class QCodeService {
* @return
* @throws IOException
*/
private
byte
[]
drawPicture
(
InputStream
qrCodeImg
,
String
goodPicUrl
,
String
goodName
)
throws
IOException
{
private
byte
[]
drawPicture
(
InputStream
qrCodeImg
,
String
goodPicUrl
,
String
goodName
)
throws
IOException
,
FontFormatException
{
//底图
ClassPathResource
redResource
=
new
ClassPathResource
(
"back.jpg"
);
BufferedImage
red
=
ImageIO
.
read
(
redResource
.
getInputStream
());
...
...
@@ -111,10 +113,12 @@ public class QCodeService {
return
bs
.
toByteArray
();
}
private
void
drawTextInImg
(
BufferedImage
baseImage
,
String
textToWrite
,
int
x
,
int
y
)
{
private
void
drawTextInImg
(
BufferedImage
baseImage
,
String
textToWrite
,
int
x
,
int
y
)
throws
IOException
,
FontFormatException
{
Graphics2D
g2D
=
(
Graphics2D
)
baseImage
.
getGraphics
();
g2D
.
setColor
(
new
Color
(
167
,
136
,
69
));
g2D
.
setFont
(
new
Font
(
"黑体"
,
Font
.
PLAIN
,
42
));
//TODO 注意,这里的字体必须安装在服务器上
g2D
.
setFont
(
new
Font
(
"Microsoft YaHei"
,
Font
.
PLAIN
,
42
));
g2D
.
setRenderingHint
(
RenderingHints
.
KEY_ANTIALIASING
,
RenderingHints
.
VALUE_ANTIALIAS_ON
);
g2D
.
drawString
(
textToWrite
,
x
,
y
);
...
...
Write
Preview
Supports
Markdown
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