List of usage examples for javax.imageio ImageIO read
public static BufferedImage read(ImageInputStream stream) throws IOException
From source file:Main.java
private static BufferedImage readImage(String folder, String fileName) throws IOException { File f = new File(folder, fileName); return ImageIO.read(f); }
From source file:Main.java
/** * Loads image from the file./*from w ww.j ava 2 s .co m*/ * @param file image file * @return loaded image * @throws IOException */ public static BufferedImage loadImage(File file) throws IOException { BufferedImage image = ImageIO.read(file); return image; }
From source file:app.utils.ImageUtilities.java
public static Image readImageFromFile(File imgFile) throws IOException { String imgName = imgFile.getName(); BufferedImage img = ImageIO.read(imgFile); Pixel[][] pixels = new Pixel[img.getWidth()][img.getHeight()]; for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { int redValue = new Color(img.getRGB(x, y)).getRed(); int greenValue = new Color(img.getRGB(x, y)).getGreen(); int blueValue = new Color(img.getRGB(x, y)).getBlue(); pixels[x][y] = new Pixel(redValue, greenValue, blueValue); }//from ww w . j av a2 s . c om } return new Image(imgName, pixels, img.getRaster().getNumDataElements()); }
From source file:com.igormaznitsa.zxpoly.utils.Utils.java
public static Image loadIcon(final String name) { final InputStream resource = findResourceOrError("com/igormaznitsa/zxpoly/icons/" + name); try {/*from w w w .ja v a 2s . c om*/ return ImageIO.read(resource); } catch (IOException ex) { throw new Error("Can't read resource icon [" + name + ']'); } finally { IOUtils.closeQuietly(resource); } }
From source file:net.cloudkit.relaxation.CaptchaTest.java
public static void main(String[] args) { // System.out.println(Color.WHITE.getRGB()); try {/*from ww w.j ava 2 s. c o m*/ File fileDirectory = new File("D:\\customs\\"); File[] files = fileDirectory.isDirectory() ? fileDirectory.listFiles() : new File[0]; for (int a = 0; a < files.length; a++) { if (files[a].isDirectory()) continue; InputStream inputStream = new FileInputStream(files[a]); BufferedImage bi = ImageIO.read(inputStream); clearBorder(bi); clearNoise(bi); // List<BufferedImage> subImgs = splitImage(bi); /* for (int i = 0; i < subImgs.size(); i++) { File imageFile = new File("D:\\images\\" + i + ".gif"); ImageIO.write(subImgs.get(i), "gif", imageFile); } */ FileOutputStream fos = new FileOutputStream("D:\\images\\" + files[a].getName().substring(0, files[a].getName().indexOf(".")) + a + ".jpg"); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos); encoder.encode(bi); fos.close(); // File file2 = new File("D:\\images\\" + a + "_" + files[a].getName()); // ImageIO.write(bi, "gif", file2); } /* CloseableHttpClient httpclient = HttpClients.createDefault(); for (int i = 0; i < 1000; i++) { HttpGet httpGet = new HttpGet("http://query.customs.gov.cn/MNFTQ/Image.aspx?" + Math.random() * 1000); CloseableHttpResponse response1 = httpclient.execute(httpGet); // The underlying HTTP connection is still held by the response object // to allow the response content to be streamed directly from the network socket. // In order to ensure correct deallocation of system resources // the user MUST call CloseableHttpResponse#close() from a finally clause. // Please note that if response content is not fully consumed the underlying // connection cannot be safely re-used and will be shut down and discarded // by the connection manager. try { System.out.println(response1.getStatusLine()); HttpEntity entity1 = response1.getEntity(); // do something useful with the response body // and ensure it is fully consumed InputStream input = entity1.getContent(); File storeFile = new File("D:\\customs\\customs"+ i +".jpg"); FileOutputStream output = new FileOutputStream(storeFile); IOUtils.copy(input, output); output.close(); EntityUtils.consume(entity1); } finally { response1.close(); } } */ } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * This method loads the input Image and returns the cleaned version * @param f - input file that will be loaded as image * @return - return cleaned loaded image as BufferedImage * @throws IOException - if error occurs during loading */// w ww. jav a2s . c o m public static BufferedImage loadAndCleanImage(File f) throws IOException { BufferedImage image = ImageIO.read(f); return blackAndLightGrayCleaning(image); }
From source file:business.Reciept.java
private static model.Image createImage(MultipartFile multiPartFile) throws Exception { byte[] byteArray = multiPartFile.getBytes(); BufferedImage image = ImageIO.read(multiPartFile.getInputStream()); int height = image.getHeight(); int width = image.getWidth(); return new model.Image(byteArray, multiPartFile.getContentType(), height, width); }
From source file:Main.java
public void createThumbnail(File file) throws Exception { BufferedImage img = ImageIO.read(file); BufferedImage thumb = new BufferedImage(100, 200, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = (Graphics2D) thumb.getGraphics(); g2d.drawImage(img, 0, 0, thumb.getWidth() - 1, thumb.getHeight() - 1, 0, 0, img.getWidth() - 1, img.getHeight() - 1, null);/*from w ww . ja va 2 s. com*/ g2d.dispose(); ImageIO.write(thumb, "PNG", new File("thumb.png")); }
From source file:Main.java
public static BufferedImage readIconImage(Class<?> clazz, String path) { Closer closer = Closer.create();/* ww w .j a v a 2 s . c o m*/ try { try { InputStream in = closer.register(clazz.getResourceAsStream(path)); if (in != null) { return ImageIO.read(in); } } finally { closer.close(); } } catch (IOException ignored) { } return null; }
From source file:Main.java
/** * @see net.yura.domination.mapstore.MapChooser#createImage(java.io.InputStream) *///from w ww . j a v a2s . co m public static BufferedImage read(InputStream in) throws IOException { try { BufferedImage img = ImageIO.read(in); if (img == null) { throw new IOException("ImageIO.read returned null"); } return img; } finally { try { in.close(); } catch (Throwable th) { } } }