Ola a todos,
Estou tendo dificuldade para retorna uma imagem modificada na servlet para o jquery
o efeito que eu quero é esse [url]http://deepliquid.com/projects/Jcrop/demos.php?demo=live_crop[/url]
na sei como retorna isso para jsp , vou postar meu codigo
na servlet
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("post");
this.doGet(req, resp);
}
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
System.out.println("get");
int t = Integer.parseInt(req.getParameter("t"));
int l = Integer.parseInt(req.getParameter("l"));
int w = Integer.parseInt(req.getParameter("w"));
int h = Integer.parseInt(req.getParameter("h"));
String imagePath = getServletContext().getRealPath("/") + req.getParameter("i");
BufferedImage outImage = ImageIO.read(new File(imagePath));
BufferedImage cropped = outImage.getSubimage(l, t, w, h);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(cropped, req.getParameter("f"), out);
ImageIO.write(
cropped,
req.getParameter("f"),
new File(getServletContext().getRealPath("")
+ System.getProperty("file.separator")
+ "miniatura.png")); // save the file with crop
// dimensions
res.setContentType("image/jpg");
ServletOutputStream wrt = res.getOutputStream();
wrt.write(out.toByteArray());
wrt.flush();
wrt.close();
$('#enviar').click(function() {
if (checkCoords()) {
$.post("ImageCrop",
{
l : $('#x').val(),
t : $('#y').val(),
w : $('#w').val(),
h : $('#h').val(),
f : $('#f').val(),
i : $('#i').val()
},
function(text) {
alert("oi");//AQUI NÃO CHEGA
});
return true;
}
//fORMULARIO
<form action="" method="get" onsubmit="return checkCoords();">
<input type="hidden" id="x" name="l" value="0"/>
<input type="hidden" id="y" name="t" value="0"/>
<input type="hidden" id="w" name="w" value="0"/>
<input type="hidden" id="h" name="h" value="0"/>
<input type="hidden" size="4" id="f" name="f" value="jpg" />
<input type="hidden" size="4" id="i" name="i" value="viewer.png" />
<input type="submit" value="Crop Image" name="enviar" id="enviar" />
</form>