Gente, é oseguinte, eu criei imagens on fly só que está mostrando apenas preto. será que alguém tem uma luz para o motivo disso?
Bom, para facilitar vou postar os mesmo códigos:
esse código é da página que chama a página que gera a imagem
...
<td><div align="center"><img src="ponteiro.jsp?VALOR=350&ESCALA=600" width="100" height="100"></div></td>
...
este código é o código da pagina que gera a imagem:
<%@ page import="java.util.*, java.text.*, xx.xxx.xx.xxxxx.xxxxxxxx.*" session="true"%>
<jsp:useBean id="ponto" class="br.com.bb.sigov.sigovInicial.ponteiro" scope="session"/>
<%!
public String validaParametro(String parametro, String valorPadrao)
{
return (( (parametro == null) || (parametro == "") || (parametro.trim().equals("") )) ? valorPadrao : parametro);
}
%>
<%
response.setContentType("image/jpeg");
response.setHeader ("Pragma", "no-cache");
response.setHeader ("Cache-Control", "no-cache");
response.setDateHeader ("Expires",0);
%>
<%! boolean retorno;%>
<%! int valor = 0;%>
<%! int escala = 0;%>
<%
valor = (int)Double.parseDouble( validaParametro((String)request.getParameter("VALOR"),"0") );
escala = (int)Double.parseDouble( validaParametro((String)request.getParameter("ESCALA"),"0") );
retorno = ponto.criaPonteiro(valor, escala ,pageContext);
System.out.println("Resultado booleno de Retorno em Ponteiro.JSP: " + retorno);
%>
este é o servlet que efetivamente gera a imagem:
/*
* ponteiro.java
*
* Created on 20 de Setembro de 2006, 15:29
*/
package xx.xxx.xx.xxxxx.xxxxxxxxx;
import java.lang.String.*;
import java.lang.*;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.PrintWriter;
import java.io.*;
import java.net.*;
import java.awt.Graphics2D.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.Graphics;
import java.awt.*;
import javax.swing.*;
import com.sun.image.codec.jpeg.*;
/**
*
* @author f9343091
* @version
*/
public class ponteiro extends HttpServlet
{
private Image fundo;
private int Raio;
private int Valor;
private int Tipo;
private int Esfera;
public boolean criaPonteiro(int Valor ,int Escala, PageContext pageContext)
throws ServletException, IOException
{
/*response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();*/
HttpServletResponse response;
response = (HttpServletResponse)pageContext.getResponse();
ServletOutputStream out = response.getOutputStream();
this.Valor = Valor;
this.Tipo = Escala;
Raio = 100/2;
Esfera = 10;
int x [] = {(Raio)-3 ,Raio,(Raio)+3};
int y [] = {Raio, (Raio*2)/5, Raio};
java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(100,100,java.awt.image.BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
// g.drawImage(fundo, 0, 0, Raio*2, Raio *2, image );
g.setColor(Color.black);
g.fillOval((Raio)-(Esfera/2), Raio -(Esfera/2), Esfera, Esfera);
double Rotacao = 0;
//--------- Manipuladção dos valores ----------------------------------
double G; // Graus
double cX, cY; // Coordenada X e Y;
g.setFont(new Font("Serif", Font.PLAIN, 10));
switch (Tipo)
{
case 600:
{
//------------ 600 pontos --------------------------------------
g.setFont(new Font("Serif", Font.PLAIN, 10));
for (double i = 0; i < 700; i+=100)
{
G = (315 * i)/600 + 290; // 273 G = (273 * i)/600 + 285; // 273
G = (G * 2 * Math.PI)/360;
cX = (double)(Raio ) - ( (double)(Raio * 0.80d) * Math.cos(G)+6 ); // 300 ,, 65
cY = (double)(Raio) - ( (double)(Raio * 0.80d) * Math.sin(G)-3 ); // 400 ,, 150
((Graphics2D)g).setPaint(Color.BLACK);
g.drawString(String.valueOf((int)i) , (int)cX, (int)cY);
}
((Graphics2D)g).setPaint(Color.BLACK);
// g.drawRect(Raio , ((Raio *3)/2)+Raio/4 , 48, 20); // 230,300,45,20
// g.drawString(String.valueOf(Valor) + " pts", Raio - 14, Raio *2 - 7 );
Rotacao = (300 * (double)Valor)/600 +210;
Rotacao = (Rotacao * 2 * Math.PI)/360;
//------------------------------------------------------------*/
}
break;
case 40 :
{
//----------- 40 pontos , de 80% a 120%-------------------------
for (double i = 60; i < 141; i+= 20)
{
if (i == 60)
G = (i - 59)*3.8 +295;
else
G = (i - 60)*3.8 +295;
G = (G * 2 * Math.PI)/360;
cX = (double)(Raio * 0.88d) - ( (double)(Raio * 0.76d) * Math.cos(G) ); // 300 ,, 65
cY = Raio - ( (double)(Raio * 0.75d) * Math.sin(G) ); // 400 ,, 150
((Graphics2D)g).setPaint(Color.BLACK);
g.drawString(String.valueOf((int)i) , (int)cX, 5+(int)cY);
}
// g.setPaint(Color.BLACK);
// g.drawString(String.valueOf(Valor) + "%", Raio - 10, Raio*2 - 10);
//Rotacao = (230 * Valor)/80 + 52;
if (Valor == 60) Valor++;
Rotacao = (double)(((double)(Valor -60 )*3.8) + 208);
Rotacao = (Rotacao * 2 * Math.PI)/360;
//--------------------------------------------------------------
}
break;
case 6 :
{
//*------------ 6 pontos ---------------------------------------
for (double i = 1; i < 7; i++)
{
G = (i * 60) +240;//292
G = (G * 2 * Math.PI)/360;
cX = (double)(Raio * 0.90d) - ( (double)(Raio * 0.70d) * Math.cos(G) ); // 300 ,, 65
cY = Raio - ( (double)(Raio * 0.75d) * Math.sin(G) ); // 400 ,, 150
((Graphics2D)g).setPaint(Color.BLACK);
g.drawString(String.valueOf((int)i) , 3+(int)cX, 3+(int)cY);
}
((Graphics2D)g).setPaint(Color.BLACK);
//g.drawString(String.valueOf(Valor) + "pts", Raio - 10, Raio*2 - 10);
Rotacao = (Valor * 60) + 150;
Rotacao = (Rotacao * 2 * Math.PI)/360;
//------------------------------------------------------------*/
}
break;
}
//--------- Fim da manipulação dos valores ----------------------------
//--------- Manipulação do ponteiro -----------------------------------
int xPoints[] = x /*{Raio , (int)(Raio * 0.95d), (int)(Raio * 1.05d)}*/;
int yPoints[] = y /*{(int)(Raio * 0.25), Raio, Raio}*/;
GeneralPath Ponteiro = new GeneralPath();
Ponteiro.moveTo(xPoints[0], yPoints[0]);
for (int k=1; k < xPoints.length; k++)
Ponteiro.lineTo(xPoints[k], yPoints[k]);
Ponteiro.closePath();
((Graphics2D)g).rotate(Rotacao, Raio, Raio); /*Math.PI/10.0 ((Valor + 232) * 2 * Math.PI/360), x,x)*/
g.setColor( Color.BLACK );
((Graphics2D)g).fill(Ponteiro);
JPEGImageEncoder codificado = JPEGCodec.createJPEGEncoder(out);
codificado.encode(image);
out.close();
return true;
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
/*protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}
/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
/* protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}*/
/** Returns a short description of the servlet.
*/
public String getServletInfo()
{
return "Short description";
}
// </editor-fold>
}
pois é, isso está mostrando um quadrado preto