1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("image/jpeg");
ServletOutputStream out = res.getOutputStream();
JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder(out);
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_BYTE_INDEXED);
Graphics2D g = image.createGraphics();
Font font = new Font("Arial", Font.PLAIN, 20);
g.setFont(font);
g.setColor(Color.white);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
FontMetrics fontMetrics = g.getFontMetrics();
int taille = s.length();
String machaine [] = new String [taille];
machaine = decoupe(s);
BufferedImage tabimage [] = new BufferedImage [taille];int longueur;int hauteur;
float angulo = 180 / taille;double angle;
for (int t=0 ; t<taille ; t++){
angle = (-(angulo * t + angulo / 2)+90);
longueur = fontMetrics.stringWidth(machaine[t]);
hauteur = fontMetrics.getHeight();
tabimage[t] = new BufferedImage(longueur, hauteur, BufferedImage.TYPE_BYTE_INDEXED);
Graphics2D graph = tabimage[t].createGraphics();
graph.setFont(font);
graph.setColor(Color.white);
graph.drawString(machaine[t],0,hauteur);
graph.rotate(angle);
}
int aux = 1;
double x;double y;
if (taille > 0)
{
int a = 250; int b = 250; int r =200;
for (int i=0; i < taille; i++) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
// x = a + r * cos(theta)
// y = b + r * sin(theta)
x = a + r * Math.cos(deg2rad((angulo * i) + (angulo/2) - 177));
y = b + r * Math.sin(deg2rad((angulo * i) + (angulo/2) - 177));
g.drawImage(tabimage[i],null,(int)x,(int)y);
}
}
enc.encode(image);
} |
Partager