List of usage examples for javax.imageio ImageIO read
public static BufferedImage read(ImageInputStream stream) throws IOException
From source file:gr.iti.mklab.reveal.forensics.maps.dwnoisevar.DWNoiseVarExtractor.java
public DWNoiseVarExtractor(String FileName) throws IOException { inputImage = ImageIO.read(new File(FileName)); getNoiseMap(); }
From source file:brut.androlib.res.decoder.Res9patchStreamDecoder.java
@Override public void decode(InputStream in, OutputStream out) throws AndrolibException { try {/* w w w. j a v a 2s. c om*/ byte[] data = IOUtils.toByteArray(in); BufferedImage im = ImageIO.read(new ByteArrayInputStream(data)); int w = im.getWidth(), h = im.getHeight(); ImageTypeSpecifier its = ImageTypeSpecifier.createFromRenderedImage(im); BufferedImage im2 = its.createBufferedImage(w + 2, h + 2); im2.getRaster().setRect(1, 1, im.getRaster()); NinePatch np = getNinePatch(data); drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight); drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom); int[] xDivs = np.xDivs; for (int i = 0; i < xDivs.length; i += 2) { drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]); } int[] yDivs = np.yDivs; for (int i = 0; i < yDivs.length; i += 2) { drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]); } ImageIO.write(im2, "png", out); } catch (IOException ex) { throw new AndrolibException(ex); } catch (NullPointerException ex) { // In my case this was triggered because a .png file was // containing a html document instead of an image. // This could be more verbose and try to MIME ? throw new AndrolibException(ex); } }
From source file:ca.sqlpower.wabit.dao.session.PNGImageConverter.java
public Image convertToComplexType(InputStream convertFrom) throws ConversionException { try {/*from w w w. j av a2s .c om*/ BufferedImage img = ImageIO.read(convertFrom); return img; } catch (Exception e) { throw new ConversionException("Cannot convert the given image", e); } }
From source file:ch.fork.AdHocRailway.ui.utils.ImageTools.java
/** * Decode string to image//from w ww . j a v a 2s . c om * * @param imageString The string to decode * @return decoded image */ public static BufferedImage decodeToImage(String imageString) { BufferedImage image = null; 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:com.spstudio.common.image.ImageUtils.java
public static String zoom(String sourcePath, String targetPath, int width, int height) throws IOException { File imageFile = new File(sourcePath); if (!imageFile.exists()) { throw new IOException("Not found the images:" + sourcePath); }//from w ww . j av a2s .com if (targetPath == null || targetPath.isEmpty()) { targetPath = sourcePath; } String format = sourcePath.substring(sourcePath.lastIndexOf(".") + 1, sourcePath.length()); BufferedImage image = ImageIO.read(imageFile); image = zoom(image, width, height); ImageIO.write(image, format, new File(targetPath)); return targetPath; }
From source file:com.pullup.app.util.ImageUtils.java
public BufferedImage readImage(String token) { String path = "C:\\pullup\\profile\\" + token + ".png"; InputStream in = null;/*from w ww . j av a 2 s . co m*/ BufferedImage image = null; try { in = new FileInputStream(new File(path)); image = ImageIO.read(in); } catch (FileNotFoundException ex) { log.severe("Could not read image: " + ex.getMessage()); } catch (IOException ex) { log.severe("Could not read image: " + ex.getMessage()); } return image; }
From source file:com.sms.server.service.ImageService.java
public BufferedImage getCoverArt(MediaElement element, Integer scale) { File imageFile;/* w w w . j a v a 2s .c o m*/ BufferedImage image; // Get directory or file parent directory if (element.getType() == MediaElementType.DIRECTORY) { imageFile = findCoverArt(new File(element.getPath())); } else { imageFile = findCoverArt(new File(element.getParentPath())); } // If cover 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:eu.europa.esig.dss.pades.signature.visible.ImageFactory.java
/** * This method returns the image size with the original parameters (the generation uses DPI) * @param imageParameters the image parameters * @return a Dimension object/* w w w . j a va2 s. co m*/ * @throws IOException */ public static Dimension getOptimalSize(SignatureImageParameters imageParameters) throws IOException { int width = 0; int height = 0; if (imageParameters.getImage() != null) { BufferedImage image = ImageIO.read(imageParameters.getImage()); width = image.getWidth(); height = image.getHeight(); } SignatureImageTextParameters textParamaters = imageParameters.getTextParameters(); if ((textParamaters != null) && StringUtils.isNotEmpty(textParamaters.getText())) { Dimension textDimension = ImageTextWriter.computeSize(textParamaters.getFont(), textParamaters.getText()); switch (textParamaters.getSignerNamePosition()) { case LEFT: case RIGHT: width += textDimension.width; height = Math.max(height, textDimension.height); break; case TOP: case BOTTOM: width = Math.max(width, textDimension.width); height += textDimension.height; break; default: break; } } return new Dimension(width, height); }
From source file:app.model.game.CoverUploadModel.java
public void uploadImage(HttpServletRequest req, Game g) throws FileUploadBase.SizeLimitExceededException, FileUploadException, SQLException, Exception { int width = 500; int height = 800; //Bild upload FileUpload upload = new FileUpload(2000 * 1024, 5000 * 1024, "C:/Users/Public/Arcade/Games/" + g.getGameID() + "/assets", "C:/Users/Public/Arcade/Games/" + g.getGameID() + "/tmp/"); File fileStatus;//from w w w.java2 s.c o m fileStatus = upload.uploadFile(req); File file = new File(fileStatus.getAbsolutePath()); BufferedImage img = ImageIO.read(file); if (img.getWidth() != width || img.getHeight() != height) { img = Scalr.resize(img, Scalr.Method.SPEED, Scalr.Mode.FIT_EXACT, 500, 800); } File destFile = new File(fileStatus.getParent() + "/" + g.getGameID() + ".jpg"); ImageIO.write(img, "jpg", destFile); g.updateState("coverupload", "complete"); String state = g.stateToJSON(); try (SQLHelper sql = new SQLHelper()) { sql.execNonQuery("UPDATE `games` SET editState='" + state + "' WHERE ID = " + g.getGameID()); } fileStatus.delete(); }
From source file:com.apitrary.orm.codec.image.ImageJPGCodec.java
/** {@inheritDoc} */ @Override/* w w w . j a va 2 s .c o m*/ public Image decode(String value) { if (value == null || value.isEmpty()) { return null; } byte[] buffer = Base64.decodeBase64(value); InputStream in = new ByteArrayInputStream(buffer); BufferedImage bImageFromConvert; try { bImageFromConvert = ImageIO.read(in); return bImageFromConvert; } catch (IOException e) { throw new RuntimeException(e); } }