package com.qxueyou.scc.org.util; 
 | 
  
 | 
import java.awt.Color; 
 | 
import java.awt.Font; 
 | 
import java.awt.FontMetrics; 
 | 
import java.awt.Graphics2D; 
 | 
import java.awt.RenderingHints; 
 | 
import java.awt.Transparency; 
 | 
import java.awt.geom.Ellipse2D; 
 | 
import java.awt.image.BufferedImage; 
 | 
  
 | 
  
 | 
/** 
 | 
 * 课程超市工具类 
 | 
 * @author xiadehu 
 | 
 * 
 | 
 */ 
 | 
public class CourseMarketUtils { 
 | 
  
 | 
    /** 
 | 
     *  
 | 
     * @param text 
 | 
     * @param bgColor 
 | 
     * @return 
 | 
     */ 
 | 
    public static BufferedImage drawPng(char letter,Color bgColor){ 
 | 
         
 | 
        //初始化画布 
 | 
        int width=120; 
 | 
        int height = 120; 
 | 
        BufferedImage image = new BufferedImage(width, height,     BufferedImage.TYPE_INT_RGB); 
 | 
        Graphics2D g2d = image.createGraphics(); 
 | 
        image = g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); 
 | 
        g2d.dispose(); 
 | 
        g2d = image.createGraphics(); 
 | 
          
 | 
        //背景 
 | 
        g2d.setColor(bgColor); 
 | 
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
 | 
        double centerX = width/2; 
 | 
        double centerY = height/2; 
 | 
        double radius = width/2; 
 | 
        Ellipse2D circle = new Ellipse2D.Double(); 
 | 
        circle.setFrameFromCenter(centerX, centerY, centerX + radius, centerY+ radius); 
 | 
        g2d.fill(circle); 
 | 
         
 | 
        //文字 
 | 
        g2d.setColor(new Color(255,255,255)); 
 | 
        int textSize = 64; 
 | 
         
 | 
        Font font = new Font("微软雅黑", Font.PLAIN, textSize); 
 | 
        g2d.setFont(font); 
 | 
        FontMetrics metrics = g2d.getFontMetrics(); 
 | 
         
 | 
        float x = (width - metrics.charWidth(letter)) / 2.0f; 
 | 
        float y = (height - metrics.getHeight()) / 2.0f + metrics.getAscent(); 
 | 
         
 | 
        g2d.drawString(String.valueOf(letter), x, y); 
 | 
         
 | 
        //释放 
 | 
        g2d.dispose(); 
 | 
         
 | 
        return image; 
 | 
    } 
 | 
     
 | 
    public static void main(String[] args){ 
 | 
        System.out.println((String)null); 
 | 
    } 
 | 
} 
 |