List of usage examples for javax.imageio ImageIO write
public static boolean write(RenderedImage im, String formatName, OutputStream output) throws IOException
From source file:com.butler.fishcartserver.ProductControler.java
@RequestMapping(value = "/product/image", method = RequestMethod.GET, produces = "image/jpg") public @ResponseBody byte[] getImage(@RequestParam(value = "name") final String product) { try {/* w w w . ja v a 2 s . co m*/ InputStream is = dao.getImage(product); BufferedImage img = ImageIO.read(is); // Create a byte array output stream. ByteArrayOutputStream bao = new ByteArrayOutputStream(); // Write to output stream ImageIO.write(img, "jpg", bao); return bao.toByteArray(); } catch (IOException ex) { Logger.getLogger(ProductControler.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:app.springapp.ConvertImageController.java
@RequestMapping(value = "/imageController/{imageId}") @ResponseBody//from w ww.j a v a2s .c om public byte[] getImage(@PathVariable int imageId) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedImage im; if (imageId == 1271) { im = img_conv.getConvertedImage(); } else { im = img_conv.getOriginalImage(); } try { ImageIO.write(im, "png", baos); } catch (IOException e) { } return baos.toByteArray(); }
From source file:com.redoute.datamap.servlet.GenerateGraph.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//w w w. ja va2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("image/png"); ServletOutputStream os = response.getOutputStream(); try { String stream = request.getParameter("stream"); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IDatamapService datamapService = appContext.getBean(IDatamapService.class); BufferedImage graph = datamapService.dataImplementedByCriteria("stream", stream); ImageIO.write(graph, "png", os); os.close(); } finally { os.close(); } }
From source file:bookpub.util.FileIO.java
public void SaveThumbnail(File file, BufferedImage thumbnail) { String fileId = file.getId().toString(); java.io.File diskFile = new java.io.File(fileDir, fileId); try {//from w w w .ja va2s . co m ImageIO.write(thumbnail, "png", diskFile); } catch (Exception e) { logger.error("Failed to save thumbnail", e); } }
From source file:com.comcast.video.dawg.show.video.BufferedImageCerealizer.java
/** * {@inheritDoc}/* www . j a v a 2 s . c om*/ */ @Override public String cerealize(BufferedImage object, ObjectCache objectCache) throws CerealException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { try { ImageIO.write(object, "jpg", baos); } catch (IOException e) { throw new CerealException("Failed to cerealize BufferedImage", e); } return Base64.encodeBase64String(baos.toByteArray()); } finally { IOUtils.closeQuietly(baos); } }
From source file:ImageUtilities.java
/** * Writes an image to an output stream as a JPEG file. * /*from w ww.ja v a 2s . c o m*/ * @param image * image to be written * @param stream * target stream * * @throws IOException * if an I/O error occured */ public static void saveImageAsJPEG(BufferedImage image, OutputStream stream) throws IOException { ImageIO.write(image, "jpg", stream); }
From source file:filters.collage.CropFilter.java
@Override protected void doFilter(BufferedImage image, OutputStream output, FilterOptions options, String format) throws IOException { com.jhlabs.image.CropFilter cropFilter = new com.jhlabs.image.CropFilter( options.get(FilterOption.X, Integer.class), options.get(FilterOption.Y, Integer.class), options.get(FilterOption.WIDTH, Integer.class), options.get(FilterOption.HEIGHT, Integer.class)); BufferedImage outputImage = new BufferedImage(options.get(FilterOption.WIDTH, Integer.class), options.get(FilterOption.HEIGHT, Integer.class), BufferedImage.TYPE_INT_RGB); cropFilter.filter(image, outputImage); ImageIO.write(outputImage, format, output); }
From source file:jadx.core.utils.android.Res9patchStreamDecoder.java
public void decode(InputStream in, OutputStream out) throws JadxException { try {//from w w w. j a v a2s .c o m byte[] data = IOUtils.toByteArray(in); BufferedImage im = ImageIO.read(new ByteArrayInputStream(data)); int w = im.getWidth(), h = im.getHeight(); BufferedImage im2 = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB); im2.createGraphics().drawImage(im, 1, 1, w, h, null); NinePatch np = getNinePatch(data); drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight); drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom); int[] xDivs = np.xDivs; for (int i = 0; i < xDivs.length; i += 2) { drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]); } int[] yDivs = np.yDivs; for (int i = 0; i < yDivs.length; i += 2) { drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]); } ImageIO.write(im2, "png", out); } catch (IOException | NullPointerException ex) { throw new JadxException(ex.toString()); } }
From source file:org.ow2.clif.jenkins.chart.AbstractChart.java
private void saveImageFile(File imageFile, BufferedImage bImage) { OutputStream os = null;// ww w .j a va 2s. c om try { os = new FileOutputStream(imageFile); ImageIO.write(bImage, "png", os); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(os); } }
From source file:org.shredzone.commons.captcha.CaptchaServlet.java
@Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { if (!request.getMethod().equals("GET")) { response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, request.getMethod() + " is not accepted"); }// ww w. j av a 2 s . c om // Prepare header response.setDateHeader("Date", System.currentTimeMillis()); response.setHeader("Cache-Control", "no-store"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/png"); // Write captcha image CaptchaService cs = getWebApplicationContext().getBean("captchaService", CaptchaService.class); BufferedImage challenge = cs.createCaptcha(request.getSession()); ImageIO.write(challenge, "png", response.getOutputStream()); }