samples
V2EX  ›  Java

Java 使用 Graphics2D 生成文字图片,如何提高清晰度?

  •  
  •   samples · Jan 9, 2019 · 4648 views
    This topic created in 2684 days ago, the information mentioned may be changed or developed.

    抗锯齿也加上了就是生成的不太清晰。

        public static void main(String[] args) throws IOException {
            File destFile = new File("D:/image/jobDetail_share.png");
            BufferedImage img = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = img.createGraphics();
            // 填充白色背景
            g.setColor(Color.white);
            g.fillRect(0, 0, img.getWidth(), img.getHeight());
            
            // 抗锯齿 添加文字
            g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
            g.setFont(new Font("微软雅黑", Font.PLAIN, 14));
            g.setPaint(new Color(103, 101, 120));
            g.drawString("长按识别小程序码", 20, 40);
            g.drawString("查看职位详情、在线投递简历", 20, 60);
            g.dispose();
    
            // 输出
            ImageIO.write(img, "png", destFile);
        }
    

    不知道怎么展示图片,先使用有道吧,捂脸: http://note.youdao.com/noteshare?id=35e44b6160aed0da4a7738e90c4578eb

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   920 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:51 · PVG 03:51 · LAX 12:51 · JFK 15:51
    ♥ Do have faith in what you're doing.