| 
 | 
 
| 
 
 1 package com.duduli.li.image; 
 2  
 3 import java.awt.Color; 
 4 import java.awt.Font; 
 5 import java.awt.Graphics; 
 6 import java.awt.image.BufferedImage; 
 7 import java.io.FileOutputStream; 
 8 import java.io.IOException; 
 9  
10 import com.sun.image.codec.jpeg.ImageFormatException; 
11 import com.sun.image.codec.jpeg.JPEGCodec; 
12 import com.sun.image.codec.jpeg.JPEGImageEncoder; 
13  
14 public class SimpleImage { 
15     public static BufferedImage getImage(){ 
16 //        image初始化 
17         BufferedImage image = new BufferedImage(60, 30, BufferedImage.TYPE_INT_RGB); 
18         Graphics graphics = image.getGraphics(); 
19 //        图片各属性设置 
20         graphics.setColor(new Color(0,255,0)); 
21         graphics.drawRect(60, 30, 60, 30); 
22         graphics.fillRect(0, 0, 60, 30); 
23         graphics.setFont(new Font("Times New Roman", Font.PLAIN, 20)); 
24 //        图片中插入字母 
25         for (int i=0; i<4; i++){  
26             String temp = "degx".substring(i, i+1);  
27                graphics.setColor(new Color(102,32,176));  
28                graphics.drawString(temp, 13 * i + 6, 16);  
29            }  
30         graphics.dispose(); 
31         return image; 
32     } 
33     /** 
34      * @param args 
35      * @throws IOException  
36      * @throws ImageFormatException  
37      */ 
38     public static void main(String[] args) throws ImageFormatException, IOException { 
39         // TODO Auto-generated method stub 
40         FileOutputStream fos = new FileOutputStream("c:\\test.jpg"); 
41         JPEGImageEncoder jie = JPEGCodec.createJPEGEncoder(fos); 
42         jie.encode(new SimpleImage().getImage()); 
43     } 
44  
45 } 
46 |   
 
 
 
 |