我想在图片上写字,我想自己设定它的颜色用RBG来确定:譬如 #FFB340 这种颜色;
字体就定义中文的字体,譬如:棣书、楷体、宋体等字体?
怎样可以设定???

解决方案 »

  1.   

    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;public class Test extends JFrame { public Test() {
    super("Test");
    BufferedImage img = new BufferedImage(200, 100, BufferedImage.TYPE_INT_BGR);
    Graphics2D g2d = img.createGraphics();
    g2d.setColor(new Color(255, 179, 64)); // #FFB340 -> R:255 G:179 B:64
    g2d.setFont(new Font("黑体", 0, 20));
    g2d.drawString("要写的文字", 50, 50);
    this.getContentPane().add(new JLabel(new ImageIcon(img)));
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(300, 200);
    this.setVisible(true);
    } public static void main(String[] arg) {
    new Test();
    }}
      

  2.   

    我知道这样可以设字体!! 我想要其他字体的样式怎样设!
    譬如象photoshop里面的字体!!
      

  3.   

    mq612(五斗米)正解
    其它的字体呀,没办法,楼主不要想着象photoshop里用字体那么方便了,再不只能做一个字体列表了。