I have a code for saving an image to database but not yet cropped, to save an image to database I'm using "FileInputStream"
FileInputStream imgByte;
File imgLocation = new File(image_location);
stmt =con.prepareStatement("INSERT INTO image(image_id, image_data, image_name, image_ext)VALUES (?, ?, ?, ?);");
imgByte = new FileInputStream(imgLocation);
stmt.setInt(1, image_id+1);
stmt.setBinaryStream(2, (InputStream)imgByte, (int)(imgLocation.length()));
stmt.setString(3, image_name);
stmt.setString(4, image_ext);
stmt.executeUpdate();
I also have a code for cropping an image and displaying the cropped image, this code is for Servlet, I also used jquery(cropped) and jsp(send data/value to servlet) to get the variables data/value("t", "l", "w", "h")
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")+"cropped.jpg"));
ServletOutputStream wrt=res.getOutputStream();
wrt.write(out.toByteArray());
wrt.flush();
wrt.close();
Now my problem is the Array of Byte in "out" variable is a "ByteArrayOutputStream" datatype how can I convert that to "FileInputStream" where the "FileInputStream" used in saving the image to database.