修改默认字体

This commit is contained in:
Menethil
2018-07-29 03:49:31 +08:00
parent 264c50e195
commit 0881acf434
2 changed files with 34 additions and 3 deletions

View File

@@ -0,0 +1,27 @@
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());
}
}

View File

@@ -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);