"...java/net/mingsoft/git@ustchcs.com:gujinli1118/MCMS.git" did not exist on "622428dbd2926c6aa10c04ad123ac0ee4583e68a"
Commit 0881acf4 authored by Menethil's avatar Menethil
Browse files

修改默认字体

parent 264c50e1
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());
}
}
...@@ -46,6 +46,8 @@ public class QCodeService { ...@@ -46,6 +46,8 @@ public class QCodeService {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (FontFormatException e) {
e.printStackTrace();
} }
} }
...@@ -66,7 +68,7 @@ public class QCodeService { ...@@ -66,7 +68,7 @@ public class QCodeService {
* @return * @return
* @throws IOException * @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"); ClassPathResource redResource = new ClassPathResource("back.jpg");
BufferedImage red = ImageIO.read(redResource.getInputStream()); BufferedImage red = ImageIO.read(redResource.getInputStream());
...@@ -111,10 +113,12 @@ public class QCodeService { ...@@ -111,10 +113,12 @@ public class QCodeService {
return bs.toByteArray(); 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(); Graphics2D g2D = (Graphics2D) baseImage.getGraphics();
g2D.setColor(new Color(167, 136, 69)); 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.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2D.drawString(textToWrite, x, y); g2D.drawString(textToWrite, x, y);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment