List of usage examples for javax.imageio ImageIO read
public static BufferedImage read(ImageInputStream stream) throws IOException
From source file:com.frostwire.gui.library.tags.AbstractTagParser.java
protected static BufferedImage imageFromData(byte[] data) { BufferedImage image = null;//from w w w . j av a2s .c o m try { try { image = ImageIO.read(new ByteArrayInputStream(data, 0, data.length)); } catch (IIOException e) { image = JPEGImageIO.read(new ByteArrayInputStream(data, 0, data.length)); } } catch (Throwable e) { LOG.error("Unable to create artwork image from bytes"); } return image; }
From source file:fi.helsinki.opintoni.service.ImageService.java
@SkipLoggingAspect public BufferedImage bytesToBufferedImage(byte[] bytes) { try {// w w w. j a v a2 s . c o m return ImageIO.read(new ByteArrayInputStream(bytes)); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.nekorp.workflow.desktop.view.resource.imp.IconProviderImp.java
@Override public JPanel getIcon(String name) { BufferedImage img = cache.get(name); if (img == null) { try {/*from ww w . j ava 2s.c om*/ ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); Resource r = resourceResolver.getResource("/icon/" + name); img = ImageIO.read(r.getInputStream()); this.cache.put(name, img); } catch (IOException ex) { throw new IllegalArgumentException("el icono no se logro cargar", ex); } } ImagenViewer panel = new ImagenViewer(img); panel.setOpaque(false); return panel; }
From source file:ImageUtilities.java
/** * Loads an image from a stream.//w w w .java2 s . co m * * @param stream * input stream * * @return the loaded image * * @throws IOException * if the image could not be loaded */ public static BufferedImage loadImage(InputStream stream) throws IOException { return ImageIO.read(stream); }
From source file:com.openbravo.pos.util.ThumbNailBuilder.java
public ThumbNailBuilder(int width, int height, String img) { Image defimg;/*w ww.j a v a 2 s . co m*/ try { init(width, height, ImageIO.read(getClass().getClassLoader().getResourceAsStream(img))); } catch (Exception fnfe) { init(width, height, null); } }
From source file:dk.netdesign.common.osgi.config.osgi.OCD.java
@Override public InputStream getIcon(int iconDimension) throws IOException { BufferedImage img = null;// w w w.j a va2 s .c o m img = ImageIO.read(iconFile); BufferedImage resizedImage = scaleImage(img, iconDimension, iconDimension, Color.DARK_GRAY); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(resizedImage, "jpg", os); return new ByteArrayInputStream(os.toByteArray()); }
From source file:com.cognifide.aet.job.common.comparators.layout.utils.ImageComparisonTest.java
@Test public void test_sameScreenshot_expectNoDifferencesInResultAndTransparentMask() throws Exception { InputStream sampleStream = null; InputStream patternStream = null; InputStream maskStream = null; InputStream expectedMaskStream = null; try {/*from w ww . j a v a2 s .com*/ // given sampleStream = getClass().getResourceAsStream("/mock/LayoutComparator/image.png"); patternStream = getClass().getResourceAsStream("/mock/LayoutComparator/image.png"); BufferedImage sample = ImageIO.read(sampleStream); BufferedImage pattern = ImageIO.read(patternStream); // when ImageComparisonResult imageComparisonResult = ImageComparison.compare(pattern, sample); // then assertThat(imageComparisonResult.isMatch(), is(true)); assertThat(imageComparisonResult.getHeightDifference(), is(0)); assertThat(imageComparisonResult.getWidthDifference(), is(0)); assertThat(imageComparisonResult.getPixelDifferenceCount(), is(0)); maskStream = imageToStream(imageComparisonResult.getResultImage()); expectedMaskStream = getClass().getResourceAsStream("/mock/LayoutComparator/mask-identical.png"); assertThat(IOUtils.contentEquals(expectedMaskStream, maskStream), is(true)); } finally { closeInputStreams(sampleStream, patternStream, maskStream, expectedMaskStream); } }
From source file:com.webpagebytes.cms.DefaultImageProcessor.java
public boolean resizeImage(WPBFileStorage cloudStorage, WPBFilePath cloudFile, int desiredSize, String outputFormat, OutputStream os) throws WPBException { InputStream is = null;/* www. ja v a 2 s.co m*/ try { //get the file content WPBFileInfo fileInfo = cloudStorage.getFileInfo(cloudFile); String type = fileInfo.getContentType().toLowerCase(); if (!type.startsWith("image")) { return false; } is = cloudStorage.getFileContent(cloudFile); BufferedImage bufImg = ImageIO.read(is); Dimension<Integer> newSize = getResizeSize(bufImg.getWidth(), bufImg.getHeight(), desiredSize); BufferedImage bdest = new BufferedImage(newSize.getX(), newSize.getY(), BufferedImage.TYPE_INT_RGB); Graphics2D g = bdest.createGraphics(); Dimension<Double> scale = getResizeScale(bufImg.getHeight(), bufImg.getWidth(), desiredSize); AffineTransform at = AffineTransform.getScaleInstance(scale.getX(), scale.getY()); g.drawRenderedImage(bufImg, at); ImageIO.write(bdest, outputFormat, os); return true; } catch (Exception e) { throw new WPBException("Cannot resize image ", e); } finally { IOUtils.closeQuietly(is); } }
From source file:me.bramhaag.discordselfbot.util.Util.java
/** * Get image from URL./*w ww. ja va2 s . c o m*/ * @param url url to get image from. * @return image. * * @throws IOException if an I/O error occurs while creating the input stream. */ @NonNull public static BufferedImage getImage(@NonNull String url) throws IOException { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestProperty("User-Agent", Constants.USER_AGENT); return ImageIO.read(connection.getInputStream()); }
From source file:com.igormaznitsa.mindmap.swing.panel.utils.ScalableIcon.java
private ScalableIcon(final String name) { final InputStream in = ScalableIcon.class.getClassLoader() .getResourceAsStream("com/igormaznitsa/mindmap/swing/panel/icons/" + name); //NOI18N try {/* w ww. ja v a 2 s . c om*/ this.baseImage = ImageIO.read(in); this.scaledCachedImage = null; this.baseScaleX = (float) BASE_WIDTH / (float) this.baseImage.getWidth(null); this.baseScaleY = (float) BASE_HEIGHT / (float) this.baseImage.getHeight(null); } catch (Exception ex) { throw new Error("Can't load resource image " + name, ex); //NOI18N } finally { IOUtils.closeQuietly(in); } }