iteye_17458 2009-10-29 21:13 采纳率: 0%
浏览 384
已采纳

怎样用java绘制弧形文字

怎样用java绘制弧形文字呢,就像印章上的那样,然后保存到一张图片里
[b]问题补充:[/b]
[code="java"]public class Test{
public static void main(String[]args) throws Exception...{

    //1.jpg是你的 主图片的路径
     InputStream is = new FileInputStream("1.jpg");


    //通过JPEG图象流创建JPEG数据流解码器
     JPEGImageDecoder jpegDecoder = JPEGCodec.createJPEGDecoder(is);
    //解码当前JPEG数据流,返回BufferedImage对象
     BufferedImage buffImg = jpegDecoder.decodeAsBufferedImage();
    //得到画笔对象
     Graphics g = buffImg.getGraphics();

    //创建你要附加的图象。
     //2.jpg是你的小图片的路径
     ImageIcon imgIcon = new ImageIcon("2.jpg"); 

    //得到Image对象。
     Image img = imgIcon.getImage();

    //将小图片绘到大图片上。
     //5,300 .表示你的小图片在大图片上的位置。
     g.drawImage(img,5,330,null);

    //设置颜色。
     g.setColor(Color.BLACK);

    //最后一个参数用来设置字体的大小
     Font f = new Font("宋体",Font.BOLD,30);
    g.setFont(f);

    //10,20 表示这段文字在图片上的位置(x,y) .第一个是你设置的内容。
     g.drawString("默哀555555。。。。。。。",10,30);
    g.dispose();

    OutputStream os = new FileOutputStream("union.jpg");
    //创键编码器,用于编码内存中的图象数据。
     JPEGImageEncoder en = JPEGCodec.createJPEGEncoder(os);
    en.encode(buffImg);
    is.close();
    os.close();
    System.out.println ("合成结束。。。。。。。。");
}    

}[/code]

我已经可以在panel上实现我想要的功能,不知道能不能把panel上东东保存为图片呢

  • 写回答

2条回答 默认 最新

  • ChocooM 2009-10-31 07:49
    关注

    [quote]我已经可以在panel上实现我想要的功能,不知道能不能把panel上东东保存为图片呢 [/quote]
    你的意思是不是在这个Panel里插入背景图片阿
    [code="java"]
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;

    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;

    public class JpanelBackGround extends JFrame{
    public JpanelBackGround(){
    super("Java.swing.Timer类测试");
    Animater animator = new Animater();
    animator.setOpaque(true);
    animator.setBackground(Color.white);
    setContentPane(animator);
    JLabel lab=new JLabel("图片显示",JLabel.CENTER);
    animator.add(lab);
    this.setSize(220, 300);
    this.setVisible(true);
    this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
    }

    public static void main(String args[]){
    new time();
    }
    }

    //给JPanel加入图片
    class Animater extends JPanel{
    Animater(){
    super(new BorderLayout());
    }
    protected void paintComponent(Graphics g){
    super.paintComponent(g);
    ImageIcon img=new ImageIcon("E:\2.jpg");
    img.paintIcon(this, g, 0, 0);
    }
    }

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作