需要Line2D装饰技巧-Graphics2D

需要Line2D装饰技巧-Graphics2D,第1张

需要Line2D装饰技巧-Graphics2D

Use a

BasicStroke
and draw it twice, thicker and thinner.

import java.awt.*;import java.awt.image.*;import java.awt.geom.*;import javax.swing.*;import javax.imageio.ImageIO;import java.io.File;class PaintThick {    public static void main(String[] args) throws Exception {        int size = 150;        final BufferedImage bi = new BufferedImage( size,size,BufferedImage.TYPE_INT_RGB);        Graphics2D g = bi.createGraphics();        double pad = 20;        Line2D.Double line1 = new Line2D.Double( pad,pad,(double)(size-pad),(double)(size-pad));        int cap = BasicStroke.CAP_BUTT;        int join = BasicStroke.JOIN_MITER;        BasicStroke thick = new BasicStroke(15,cap,join);        BasicStroke thinner = new BasicStroke(13,cap,join);        g.setColor(Color.WHITE);        g.fillRect(0,0,size,size);        g.setColor(Color.BLACK);        g.setStroke(thick);        g.draw(line1);        g.setColor(Color.WHITE);        g.setStroke(thinner);        g.draw(line1);        ImageIO.write(bi,"png",new File("img.png"));        SwingUtilities.invokeLater(new Runnable() { public void run() {     JOptionPane.showMessageDialog(         null, new JLabel(new ImageIcon(bi))); }        });    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5091760.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存