1 package org.activiti.examples.processdefinitions;
2
3 import java.awt.Font;
4 import java.awt.FontMetrics;
5 import java.awt.Graphics2D;
6 import java.awt.image.BufferedImage;
7 import java.io.File;
8 import java.io.IOException;
9
10 import javax.imageio.ImageIO;
11
12 public class Test {
13
14 /**
15 * @param args
16 */
17 public static void main(String[] args) {
18 int width = 100;
19 int height = 100;
20 String text = "鐖辨垜涓崕";
21 int x = 0;
22 int y = 0;
23 BufferedImage processDiagram = new BufferedImage(100, 100,
24 BufferedImage.TYPE_INT_ARGB);
25 Graphics2D g = (Graphics2D) processDiagram.createGraphics();
26 Font font = new Font("瀹嬩綋", Font.BOLD, 12);
27 g.setFont(font);
28 FontMetrics fontMetrics = g.getFontMetrics();
29 int textX = x + ((width - fontMetrics.stringWidth(text)) / 2);
30 int textY = y + ((height - fontMetrics.getHeight()) / 2)
31 + fontMetrics.getHeight();
32 g.drawString(text, textX, textY);
33 File outFile = new File("d:/newfile.png");
34 try {
35 ImageIO.write(processDiagram, "png", outFile);
36 } catch (IOException e) {
37 // TODO Auto-generated catch block
38 e.printStackTrace();
39 }// 鍐欏浘鐗?/span>
40 }
41
42 }
43
鎼炲畾錛屽懙鍛點?br />濡傛灉瑕侀儴緗插埌linux鐜鐨勮瘽錛岄渶瑕佸皢鐩稿叧鐨勫瓧浣撴枃浠朵紶鍒版湇鍔″櫒鐨刯dk涓嬪嵆鍙?br />鎴戠殑鏈湴瀛椾綋鏂囦歡鍦板潃鏄?#8220;C:\WINDOWS\Fonts\simsun.ttc”錛?br />涓婁紶鍒版湇鍔″櫒鍦板潃鏄細“/usr/jdk/instances/jdk1.5.0/jre/lib/fonts/simsun.ttc”
鍒氭墠璇曚簡涓涓嬶紝鍙互涓嶇敤鎸囧畾瀛椾綋錛屽氨鑳借В鍐充貢鐮佺殑闂錛屽綋鐒訛紝鎴戣寰楀簲璇ヨ嚜鍔ㄥ拰鎿嶄綔緋葷粺鐨勫瓧浣撶浉鍏沖惂銆傚鏋滄搷浣滅郴緇焜dk涓嶆敮鎸佷腑鏂囷紝涔熷簲璇ヤ貢鐮併?/span>

]]>