Estou tentando gerar miniaturas das imagens mas não estou entendendo pq em java se utiliza tipos bytes, eu salvei apenas o nome das imagens no banco de dados e pretendia gerar a thumb com alguma classe já pronta, o problema é que o que eu tenho visto na net utiliza bytes, não sei como a imagem fica guarda no bd assim.
Esse foi o ultima classe que achei pra gerar as thumbnails, mas não rolou pelo motivo que falei.
package pack.vinhos.control;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class ImageGetter extends HttpServlet {
public static void main(String[] args) {
}
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String productNumber = null;
productNumber = request.getParameter("idImg");
getImage(response, productNumber);
}
public void getImage(HttpServletResponse response,
String productNumber) throws ServletException, IOException {
try {
//setup the database connection
Connection imageConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/teste", "root", "");
//SQL statement to query the database
PreparedStatement imagePS = imageConn.prepareCall("SELECT img FROM vinhos WHERE id = '" + productNumber + "'");
imagePS.setQueryTimeout(0);
//the ResultSet object to hold the query results
ResultSet RSImage = imagePS.executeQuery();
//create a boolean datatype that is initialized to //true if the ResultSet is empty (no image found)
boolean noRecords = !RSImage.next();
//if the ResultSet is empty, close it
if (noRecords) {
RSImage.close();
} else { //if it contains data, go ahead with the image //fetching
//set the content type for an image (image/gif //will still display jpgs and possibly bmps
//in Internet Explorer)
response.setContentType("image/gif");
ServletOutputStream out = response.getOutputStream();
//getBytes is a method of class ResultSet used //to read the ResultSet data into an array of //bytes. This is where the image gets pulled //from the database into an array we can work //with in our code.
byte imageByteArray[] = RSImage.getBytes("img");
//String imgByte = "http://localhost:8080/teste/images/" + RSImage.getString("img");
//byte imageByteArray[] = imgByte.getBytes();
//the content length is set to the length of //the byte array
response.setContentLength(imageByteArray.length);
//the byte array is written to the //ServletOutputStream starting with the first //byte and ending with the last
out.write(imageByteArray, 0, imageByteArray.length);
//The ServletOutputStream is flushed, the //recordset is closed, and the connection is //closed.
out.flush();
RSImage.close();
}
imageConn.close();
} catch (Exception ex) {
}
}
}
Alguém sabe de uma classe pra isso?
Tipo a timthumbs do php
Obrigado
