List of usage examples for javax.imageio ImageIO read
public static BufferedImage read(ImageInputStream stream) throws IOException
From source file:de.kp.ames.web.function.dms.cache.ImageCacheManager.java
public void setToCache(String key, String name, String mimetype, InputStream stream) throws IOException { DmsImage image = new DmsImage(key, name, mimetype, ImageIO.read(stream)); cache.put(key, image);/*from w w w . ja va 2s . com*/ }
From source file:com.company.project.web.controller.WebSocketController.java
@MessageMapping("/imageFileShareMapping") @SendTo("/topic/imageFileShareResponse") public String imageFileShare(String param) throws Exception { BufferedImage image = null;/* w w w .j a va2 s . c o m*/ byte[] imageByte; try { BASE64Decoder decoder = new BASE64Decoder(); imageByte = decoder.decodeBuffer(param.split(",")[1]); ByteArrayInputStream bis = new ByteArrayInputStream(imageByte); image = ImageIO.read(bis); bis.close(); } catch (Exception e) { e.printStackTrace(); } File outputfile = new File("D:/GemShelf/" + UUID.randomUUID() + ".jpg"); ImageIO.write(image, "jpg", outputfile); return param; }
From source file:de.mpg.imeji.logic.storage.util.ImageUtils.java
/** * Prepare the image for the upload: <br/> * if it is original image upload, do nothing <br/> * if it is another resolution, resize it <br/> * if it is a tiff to be resized, transformed it to jpeg and resize it * //w w w . j ava2 s. c om * @param stream * @param contentCategory * @param format * @return * @throws IOException * @throws Exception */ public static byte[] transformImage(byte[] bytes, FileResolution resolution, String mimeType) throws IOException, Exception { // If it is orginal resolution, don't touch the file, otherwise transform (compress and/or ) if (!FileResolution.ORIGINAL.equals(resolution)) { if (FileResolution.THUMBNAIL.equals(resolution) || StorageUtils.getMimeType("tif").equals(mimeType)) { // If it is the thumbnail, compress the images (in jpeg), if it is a tif compress even for WEb // resolution, since resizing not possible with tif byte[] compressed = compressImage(bytes, mimeType); if (!Arrays.equals(compressed, bytes)) { mimeType = StorageUtils.getMimeType("jpg"); } bytes = compressed; } // Read the bytes as BufferedImage BufferedImage image; if (StorageUtils.getMimeType("jpg").equals(mimeType)) { image = JpegUtils.readJpeg(bytes); } else { image = ImageIO.read(new ByteArrayInputStream(bytes)); } if (image == null) { // The image couldn't be read return null; } // Resize image if (StorageUtils.getMimeType("gif").equals(mimeType) && GifUtils.isAnimatedGif(bytes)) { // If it is an animated gif, resize all frame and build a new gif with this resized frames bytes = GifUtils.resizeAnimatedGif(bytes, resolution); } else { bytes = toBytes(scaleImage(image, resolution), mimeType); } } return bytes; }
From source file:com.edduarte.protbox.core.Constants.java
public static BufferedImage getAsset(String resourceFileName) { BufferedImage result = cachedAssets.get(resourceFileName); if (result == null) { try {//from w w w .j a va 2s . com InputStream stream = Protbox.class.getResourceAsStream(resourceFileName); result = ImageIO.read(stream); cachedAssets.put(resourceFileName, result); } catch (IOException | IllegalArgumentException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Asset file " + resourceFileName + " not detected or corrupted!\n" + "Please reinstall the application.", "Nonexistent or corrupted asset file", JOptionPane.ERROR_MESSAGE); System.exit(1); } } return result; }
From source file:MinimalServerTest.java
License:asdf
@Override protected void setUp() throws Exception { super.setUp(); //creates mew session for unit tests String[] _judges = new String[5]; _judges[0] = "Johan"; _judges[1] = "test"; _judges[2] = "test123"; _judges[3] = "Test3"; _judges[4] = "Test4"; String[] tmp1 = new String[1]; tmp1[0] = "helo"; linkedList tmp2 = new linkedList(); tmp2.info = "stellies.jpg"; BufferedImage[] tmp3 = new BufferedImage[1]; tmp3[0] = ImageIO.read(new File("stellies.jpg")); Session tmp = new Session(tmp2, tmp3, _judges, 10, 0, false, false, tmp1); server = new MinimalServer(tmp); }
From source file:com.sishistorico.sv.SvCadastraEleitor.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . j a v a2s. c o 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 doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF8"); response.setContentType("text/html;charset=UTF-8"); List<FileItem> items = null; byte[] foto = null; try { items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { InputStream imageInput = item.getInputStream(); Image image = ImageIO.read(imageInput); BufferedImage thumb = Imagem.redimensionar(image, 400, 500); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(thumb, "JPG", baos); baos.flush(); foto = baos.toByteArray(); baos.close(); } } //dados do formulrio e metodos para salvar DateFormat formatter; Date date; formatter = new SimpleDateFormat("dd/MM/yyyy"); date = (Date) formatter.parse(items.get(1).getString()); // fim do tratamento Eleitor el = new Eleitor(); Endereco end = new Endereco(); el.setNome(items.get(0).getString("UTF-8").trim()); el.setData_nascimento(date); el.setCpf(items.get(2).getString("UTF-8").replaceAll("\\.|\\-|\\ ", "").trim()); el.setRg(items.get(3).getString("UTF-8").replaceAll("\\.|\\-|\\ ", "").trim()); el.setSus(items.get(4).getString("UTF-8").replaceAll("\\.|\\-|\\ ", "").trim()); el.setEmail(items.get(5).getString("UTF-8")); el.setTelefone(items.get(6).getString("UTF-8").replaceAll("\\(|\\)|\\-|\\ ", "").trim()); el.setWhats(items.get(7).getString("UTF-8").replaceAll("\\(|\\)|\\-|\\ ", "").trim()); el.setObs(items.get(8).getString("UTF-8").trim()); el.setReferencia_pessoal(items.get(9).getString("UTF-8").trim()); end.setRua(items.get(11).getString("UTF-8").trim()); end.setBairro(items.get(12).getString("UTF-8").trim()); end.setN(items.get(13).getString("UTF-8").trim()); end.setCidade(items.get(14).getString("UTF-8").trim()); end.setCep(items.get(15).getString("UTF-8").trim()); end.setLocalidade(Integer.parseInt(items.get(16).getString("UTF-8").trim())); el.setTipo(Integer.parseInt(items.get(17).getString("UTF-8").trim())); el.setPertence(Integer.parseInt(items.get(18).getString("UTF-8").trim())); el.setEnd(end); DaoEleitor daoEleitor = new DaoEleitor(); DaoFoto daoFoto = new DaoFoto(); int idretorno = daoEleitor.Eleitor_Salvar(el); daoFoto.inserirImagem(foto, idretorno); response.sendRedirect("cadastro_eleitor.jsp?msgok"); } catch (FileUploadException ex) { Logger.getLogger(SvCadastraEleitor.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(SvCadastraEleitor.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(SvCadastraEleitor.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(SvCadastraEleitor.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.sms.server.service.ImageService.java
public BufferedImage getFanArt(MediaElement element, Integer scale) { File imageFile;//from www . ja v a 2 s. c o m BufferedImage image; // Get directory or file parent directory if (element.getType() == MediaElementType.DIRECTORY) { imageFile = findFanArt(new File(element.getPath())); } else { imageFile = findFanArt(new File(element.getParentPath())); } // If fan art is not found return. if (imageFile == null) { return null; } // Read image file into buffer try { image = ImageIO.read(imageFile); } catch (IOException ex) { LogService.getInstance().addLogEntry(LogService.Level.ERROR, CLASS_NAME, "Failed to read image file " + imageFile.getPath(), ex); return null; } // Scale image image = Scalr.resize(image, scale); return image; }
From source file:com.seleniumtests.util.imaging.ImageProcessor.java
/** * Agregate 2 pictures/*w ww . jav a 2 s . c o m*/ * @param imgf1 first picture to agregate * @param imgf2 seconde picture to aggregate * @param finalImage file to create * @param img2PosX X coord where second picture will be but, relative to first one * @param img2PosY Y coord where second picture will be but, relative to first one */ public static void concat(File imgf1, File imgf2, File finalImage, Integer img2PosX, Integer img2PosY) { try { BufferedImage img1 = ImageIO.read(imgf1); BufferedImage img2 = ImageIO.read(imgf2); ImageIO.write(concat(img1, img2, img2PosX, img2PosY), "jpg", finalImage); } catch (IOException e) { } }
From source file:edworld.pdfreader4humans.PDFReaderTest.java
@Test public void createPageImageWithoutStructure() throws IOException { File outputFile = new File("target/outputWithoutStructure.png"); ImageIO.write(reader.createPageImage(1, 3, Color.BLACK, Color.WHITE, false), "png", outputFile); assertImagesAreSimilar(getClass().getResourceAsStream("/testcase1/outputWithoutStructure.png"), ImageIO.read(outputFile)); }
From source file:ScalingMethods.java
/** Creates a new instance of ScalingMethods */ public ScalingMethods() { try {/*from w ww. ja v a2s. co m*/ URL url = getClass().getResource("BB.jpg"); picture = ImageIO.read(url); scaleW = (int) (SCALE_FACTOR * picture.getWidth()); scaleH = (int) (SCALE_FACTOR * picture.getHeight()); setPreferredSize(new Dimension(PADDING + (5 * (scaleW + PADDING)), scaleH + (2 * PADDING))); } catch (Exception e) { System.out.println("Problem reading image file: " + e); System.exit(0); } }