public class ImgTest{
public static void main(String[] args) throws Exception{
final String str = "这是一个测试我想有个老婆";
final int x = 150;
final int y = 150;
final int d = 100;
BufferedImage bi = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
g2d.setBackground(Color.BLACK);
g2d.setColor(Color.white);
//半圆,如果想是一个圆的话,×2
double pre = Math.PI*2/str.length();
for(int i=0;i<str.length();i++){
AffineTransform rot = new AffineTransform();
rot.rotate(pre,x,y);
public class ImgTest{
public static void main(String[] args) throws Exception{
final String str = "这是一个测试";
final int x = 150;
final int y = 150;
final int d = 100;
BufferedImage bi = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
g2d.setBackground(Color.BLACK);
g2d.setColor(Color.white);
for(int i=0;i<str.length();i++){
double jd=((Math.PI*2)/str.length())*i;
g2d.drawString(str.substring(i,i+1),(float)(x+Math.sin(jd)*d),(float)(y-Math.cos(jd)*d));
}
//output image
FileOutputStream output = new FileOutputStream(new File("C:\\test.jpg"));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
encoder.encode(bi);
output.close();
}
}