List of usage examples for javax.imageio ImageIO read
public static BufferedImage read(ImageInputStream stream) throws IOException
From source file:filters.BaseFilter.java
public void filter(URL url, OutputStream output, FilterOptions options) throws IOException, EmptyExtensionException, NotSupportedFormatException, FileTooBigException { String format = SupportedFormats.supportFormat(url.toString()); if (StringUtils.isBlank(format)) { throw new NotSupportedFormatException(); }/*from www .jav a2 s . c om*/ // Calculate size HttpURLConnection openConnection = (HttpURLConnection) url.openConnection(); int contentLength = openConnection.getContentLength(); if (contentLength > FILE_SIZE_LIMIT) { throw new FileTooBigException(); } openConnection.disconnect(); BufferedImage read = ImageIO.read(url); doFilter(read, output, options, format); }
From source file:com.igormaznitsa.mindmap.swing.services.DefaultImageIconService.java
@Nonnull private static Icon loadIcon(@Nonnull final String name) { final InputStream in = ScalableIcon.class.getClassLoader() .getResourceAsStream("com/igormaznitsa/mindmap/swing/panel/icons/" + name); //NOI18N try {/* w w w .ja v a 2s. c o m*/ return new ImageIcon(ImageIO.read(in)); } catch (IOException ex) { throw new Error("Can't load icon " + name, ex); //NOI18N } finally { IOUtils.closeQuietly(in); } }
From source file:es.logongas.util.seguridad.CodigoVerificacionSeguro.java
/** * Crea un cdigo de verificacin seguro nico a paritr de una imagen que * est en un array de datos/*from w ww . j av a 2 s .co m*/ * * @param imageInputStream Los bytes de la imagen * @return El cdigo de verificacin seguro */ public static CodigoVerificacionSeguro getInstanceFromImageQRCode(InputStream imageInputStream) { try { BufferedImage originalImage = ImageIO.read(imageInputStream); BufferedImage image = resizeImage(originalImage, 0.5); //Hacemos mas pequea la imagen pq sino no lee bien el cdigo. LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader qRCodeReader = new QRCodeReader(); Result result = qRCodeReader.decode(bitmap); return new CodigoVerificacionSeguro(String.valueOf(result.getText())); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:gui.Grafico.java
/** * Creates new form Grafico// w w w . j a va2 s . c om */ public Grafico() { initComponents(); try { setIconImage(ImageIO.read(getClass().getResource("/gui/Graph.png"))); } catch (IOException ex) { Logger.getLogger(VentanaCalculo.class.getName()).log(Level.SEVERE, null, ex); } finally { setLocationRelativeTo(null); } }
From source file:com.ckfinder.connector.utils.ImageUtils.java
/** * create thumb file./*from ww w .j av a 2s . co m*/ * * @param orginFile orgin image file. * @param file file to save thumb * @param conf connector configuration * @throws IOException when error occurs. */ public static void createThumb(final File orginFile, final File file, final IConfiguration conf) throws IOException { BufferedImage image = ImageIO.read(orginFile); if (image != null) { Dimension dimension = createThumbDimension(image, conf.getMaxThumbWidth(), conf.getMaxThumbHeight()); FileUtils.createPath(file, conf, true); if (image.getHeight() == dimension.height && image.getWidth() == dimension.width) { writeUntouchedImage(orginFile, file); } else { resizeImage(image, dimension.width, dimension.height, conf.getThumbsQuality(), file); } } else { if (conf.isDebugMode()) { throw new IOException("Wrong image file"); } } }
From source file:com.betel.flowers.web.bean.util.UploadFileRun.java
@Override public void run() { Boolean succesefull = Boolean.FALSE; Path path = Paths.get(url); //if directory exists? if (!Files.exists(path)) { try {//from ww w. ja va 2s. c o m Files.createDirectories(path); log.log(Level.INFO, "Directory is created!"); } catch (IOException e) { //fail to create directory log.log(Level.SEVERE, "Failed to create directory! " + e.getMessage()); } } File fileDelete = new File(url + name + "." + ext); if (fileDelete.delete()) { log.log(Level.INFO, "Se elimino el archivo: " + url + name + "." + ext); } else { log.log(Level.INFO, "No se elimino el archivo: " + url + name + "." + ext); } File file = new File(url + name + "." + ext); try { byte[] imgbytes = IOUtils.toByteArray(input); InputStream in = new ByteArrayInputStream(imgbytes); BufferedImage bImageFromConvert = ImageIO.read(in); ImageIO.write(bImageFromConvert, ext, file); succesefull = Boolean.TRUE; } catch (IOException e) { log.log(Level.SEVERE, "Error al guardar la imagen en:" + file.getPath(), e); } if (succesefull) { try { this.finalize(); this.exito = true; } catch (Throwable ex) { log.log(Level.SEVERE, "Error al procesar imagen", ex); } } else { this.interrupt(); this.exito = false; } }
From source file:com.reydentx.core.common.JSONUtils.java
private static BufferedImage decodeToImage(String imageString) { BufferedImage image = null;/*from w w w . ja va 2 s . co m*/ byte[] imageByte; try { imageByte = Base64.decodeBase64(imageString); ByteArrayInputStream bis = new ByteArrayInputStream(imageByte); image = ImageIO.read(bis); bis.close(); } catch (Exception e) { e.printStackTrace(); } return image; }
From source file:be.fedict.eid.idp.sp.PhotoServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.debug("doGet"); response.setContentType("image/jpg"); response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1 response.setHeader("Pragma", "no-cache, no-store"); // http 1.0 response.setDateHeader("Expires", -1); ServletOutputStream out = response.getOutputStream(); HttpSession session = request.getSession(); byte[] photoData = (byte[]) session.getAttribute(PHOTO_SESSION_ATTRIBUTE); if (null != photoData) { BufferedImage photo = ImageIO.read(new ByteArrayInputStream(photoData)); if (null == photo) { /*//from ww w. j a va 2s . c om * In this case we render a photo containing some error message. */ photo = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) photo.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setColor(Color.RED); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.drawString("Photo Error", 0, 200 / 2); graphics.dispose(); ImageIO.write(photo, "jpg", out); } else { out.write(photoData); } } out.close(); }
From source file:com.fun.util.TesseractUtil.java
/** * //from ww w . j av a 2 s.com * * @param imageFile * @param times * @param targetFile * @throws IOException */ private static void scaled(File imageFile, int times, File targetFile) throws IOException { BufferedImage image = ImageIO.read(imageFile); int targetWidth = image.getWidth() * times; int targetHeight = image.getHeight() * times; int type = (image.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage tmp = new BufferedImage(targetWidth, targetHeight, type); Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(image, 0, 0, targetWidth, targetHeight, null); g2.dispose(); ImageIO.write(tmp, "png", targetFile); }
From source file:com.ables.pix.utility.PictureOps.java
private void rotatePicture(Picture pic, double rotation) { ResourceLoader loader = new FileSystemResourceLoader(); Resource resource = loader.getResource(repositoryRoot + pic.getLocation()); BufferedImage image;// ww w . j a va 2 s .c o m try { image = ImageIO.read(resource.getFile()); BufferedImage result = tilt(image, rotation); String fileName = pic.getFileName(); ImageIO.write(result, fileName.substring(fileName.indexOf('.' + 1)), new File(resource.getFile().toURI())); } catch (IOException io) { throw new RuntimeException("Failed to rotate image", io); } }