List of usage examples for javax.imageio ImageIO read
public static BufferedImage read(ImageInputStream stream) throws IOException
From source file:UserInterface.AdministrativeRole.FeedBackJPanel.java
private void backgroundImage(String str) { try {//ww w.jav a2s.c om BufferedImage image1 = ImageIO.read(ManageNetworkJPanel.class.getResource(str)); image2 = image1.getScaledInstance(1200, 800, Image.SCALE_SMOOTH); } catch (IOException ex) { Logger.getLogger(SignUpJPanel.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.liusoft.dlog4j.util.ImageUtils.java
/** * ?/*from ww w . j a v a2 s .c o m*/ * @param orig_img * @param obj_filename * @param p_width * @param p_height * @throws IOException */ public static String createPreviewImage(InputStream orig_img, String obj_filename, int p_width, int p_height) throws IOException { String extendName = StringUtils.getFileExtend(obj_filename).toLowerCase(); FileOutputStream newimage = null; InputStream fis = orig_img; try { if ("gif".equalsIgnoreCase(extendName)) { GifImage gifImage = GifDecoder.decode(fis); fis.close(); fis = null; GifImage newGif = GifTransformer.resize(gifImage, p_width, p_height, false); newimage = new FileOutputStream(obj_filename); GifEncoder.encode(newGif, newimage); } else { BufferedImage orig_portrait = (BufferedImage) ImageIO.read(fis); fis.close(); fis = null; // ?JPG? BufferedImage bi = new BufferedImage(p_width, p_height, BufferedImage.TYPE_INT_RGB); bi.getGraphics().drawImage(orig_portrait, 0, 0, p_width, p_height, null); if (!obj_filename.endsWith(".jpg")) obj_filename += ".jpg"; newimage = new FileOutputStream(obj_filename); ImageIO.write(bi, "jpg", newimage); } } finally { if (newimage != null) newimage.close(); if (fis != null) fis.close(); } return obj_filename; }
From source file:view.statistics.IssueChart.java
/** * Creates new form IssueChart/*from w w w .j a va 2 s.c om*/ */ public IssueChart(Dimension d) throws FileNotFoundException, IOException { initComponents(); FileInputStream imgStream = null; File imgfile = new File("..\\BBMS\\src\\images\\drop.png"); imgStream = new FileInputStream(imgfile); BufferedImage bi = ImageIO.read(imgStream); ImageIcon myImg = new ImageIcon(bi); this.setFrameIcon(myImg); setTitle("Issue Chart"); setSize(d); }
From source file:edworld.pdfreader4humans.PDFReaderTest.java
@Test public void createPageImageWithStructure() throws IOException { File outputFile = new File("target/outputWithStructure.png"); ImageIO.write(reader.createPageImage(1, 3, Color.WHITE, Color.BLACK, true), "png", outputFile); assertImagesAreSimilar(getClass().getResourceAsStream("/testcase1/outputWithStructure.png"), ImageIO.read(outputFile)); }
From source file:com.netflix.imfutility.itunes.image.ImageValidator.java
private void ensureReadImage() throws ImageValidationException { if (image != null) { return;// w w w . j av a 2s. co m } try { image = ImageIO.read(file); if (image == null) { throw new ImageValidationException( String.format("Can't read %s image from file %s", imageType, file.getName())); } } catch (IOException e) { throw new ImageValidationException( String.format("Can't read %s image from file %s", imageType, file.getName()), e); } }
From source file:software.uncharted.rest.ImageSearchResource.java
@RequestMapping(value = "/file", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ImageSearchResult searchByFile(@RequestParam("image") final MultipartFile file) throws IOException { long start = System.nanoTime(); String fileType = file.getContentType(); if (fileType.startsWith("image")) { BufferedImage image = ImageIO.read(file.getInputStream()); Set<Image> images = service.search(image); long duration = (System.nanoTime() - start) / 1000000L; return new ImageSearchResult().setImages(images).setDuration(duration); }/* w w w. jav a 2s . co m*/ return ImageSearchResult.empty(); }
From source file:JumbledImage.java
public JumbledImage(URL imageSrc) { try {/*from w w w . j a va 2s . c om*/ bi = ImageIO.read(imageSrc); w = bi.getWidth(null); h = bi.getHeight(null); } catch (IOException e) { System.out.println("Image could not be read"); System.exit(1); } cw = w / numlocs; ch = h / numlocs; cells = new int[numcells]; for (int i = 0; i < numcells; i++) { cells[i] = i; } }
From source file:app.springapp.ImageConverter.java
public void loadImage(String filepath) { try {/*w ww . j a v a 2s. c o m*/ org_image = ImageIO.read(new File(filepath)); } catch (IOException e) { System.out.println("Could not read image! :" + e.getMessage()); } }
From source file:mysynopsis.ImageProcess.java
public static BufferedImage toBufferedImage() throws IOException { BufferedImage bufferedImage = null; try {/*from ww w . j a v a2s . c o m*/ byte[] byteArray = Base64.decodeBase64(Variables.imgString); try (InputStream in = new ByteArrayInputStream(byteArray)) { bufferedImage = ImageIO.read(in); } } catch (IOException iOException) { return null; } return bufferedImage; }
From source file:com.mycompany.memegenerator.FileUpload.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww . ja v a 2 s .c om*/ * * @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 { if (ServletFileUpload.isMultipartContent(request)) { try { List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { String name = new File(item.getName()).getName(); byte[] byteImage = item.get(); uploadImage = ImageIO.read(new ByteArrayInputStream(byteImage)); //ImageIO.write(uploadImage, "jpg", new File("C:\\uploads","snap.jpg")); // get session HttpSession session = request.getSession(); session.setAttribute("byteImage", byteImage); session.setAttribute("uploadImage", uploadImage); } } //File uploaded successfully request.setAttribute("message", "File Uploaded Successfully"); } catch (Exception ex) { request.setAttribute("message", "File Upload Failed due to " + ex); } } else { request.setAttribute("message", "Sorry this Servlet only handles file upload request"); } request.getRequestDispatcher("/index.jsp").forward(request, response); }