List of usage examples for java.awt.image BufferedImage getWidth
public int getWidth()
From source file:de.mprengemann.intellij.plugin.androidicons.util.ImageUtils.java
private static BufferedImage ensureJpgCompatibility(BufferedImage image) { BufferedImage imageRGB = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = imageRGB.createGraphics(); g2.drawImage(image, 0, 0, imageRGB.getWidth(), imageRGB.getHeight(), Color.WHITE, null); g2.dispose();// w w w . j av a 2s .c om return imageRGB; }
From source file:com.reydentx.core.common.PhotoUtils.java
public static boolean isBlackJPEG(BufferedImage bi) { if (bi != null) { int height = bi.getHeight(); int width = bi.getWidth(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (bi.getRGB(x, y) != -16777216) { return false; }/* w ww . ja v a 2s . c o m*/ } } } return true; }
From source file:editeurpanovisu.ReadWriteImage.java
/** * * @param img// w w w . j a va2s. com * @param destFile * @param sharpen * @param sharpenLevel * @throws IOException */ public static void writePng(Image img, String destFile, boolean sharpen, float sharpenLevel) throws IOException { sharpenMatrix = calculeSharpenMatrix(sharpenLevel); BufferedImage imageRGBSharpen = null; IIOImage iioImage = null; BufferedImage image = SwingFXUtils.fromFXImage(img, null); // Get buffered image. BufferedImage imageRGB = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.BITMASK); Graphics2D graphics = imageRGB.createGraphics(); graphics.drawImage(image, 0, 0, null); if (sharpen) { imageRGBSharpen = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB); Kernel kernel = new Kernel(3, 3, sharpenMatrix); ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); cop.filter(imageRGB, imageRGBSharpen); } ImageWriter writer = null; FileImageOutputStream output = null; try { writer = ImageIO.getImageWritersByFormatName("png").next(); ImageWriteParam param = writer.getDefaultWriteParam(); output = new FileImageOutputStream(new File(destFile)); writer.setOutput(output); if (sharpen) { iioImage = new IIOImage(imageRGBSharpen, null, null); } else { iioImage = new IIOImage(imageRGB, null, null); } writer.write(null, iioImage, param); } catch (IOException ex) { throw ex; } finally { if (writer != null) { writer.dispose(); } if (output != null) { output.close(); } } graphics.dispose(); }
From source file:edu.nps.moves.mmowgli.modules.userprofile.InstallImageDialog.java
public static MediaImage putFileImageIntoDbTL(File f, String name, String mimeType) throws IOException { Image imgObj = new Image(name, mimeType); FileInputStream fis = new FileInputStream(f); byte[] ba = IOUtils.toByteArray(fis); imgObj.setBytes(ba);//from ww w. j av a2s .co m InputStream bain = new ByteArrayInputStream(ba); BufferedImage bimg = ImageIO.read(bain); imgObj.setWidth(bimg.getWidth()); imgObj.setHeight(bimg.getHeight()); Image.saveTL(imgObj); Media med = new Media(); med.setDescription(imgObj.getName() + " in db"); med.setSource(Media.Source.DATABASE); med.setType(MediaType.IMAGE); med.setHandle("" + bimg.getWidth() + "x" + bimg.getHeight()); med.setUrl(imgObj.getName()); med.setWidth((long) bimg.getWidth()); med.setHeight((long) bimg.getHeight()); Media.saveTL(med); return new MediaImage(med, imgObj); }
From source file:com.afis.jx.ckfinder.connector.utils.ImageUtils.java
/** * check if image size isn't bigger then biggest allowed. * * @param stream temp file input stream. * @param conf connector configuration./*from w w w . ja v a 2 s . co m*/ * @return true if image size isn't bigger then biggest allowed. * @throws IOException when error occurs during reading image. */ public static boolean checkImageSize(final InputStream stream, final IConfiguration conf) throws IOException { final Integer maxWidth = conf.getImgWidth(); final Integer maxHeight = conf.getImgHeight(); if (maxHeight == 0 && maxWidth == 0) { return true; } BufferedImage bi = ImageIO.read(stream); stream.close(); if (bi == null) { return false; } return (bi.getHeight() <= maxHeight && bi.getWidth() <= maxWidth); }
From source file:editeurpanovisu.ReadWriteImage.java
/** * * @param img/*from w ww . java 2 s . c o m*/ * @param destFile * @param sharpen * @param sharpenLevel * @throws IOException */ public static void writeBMP(Image img, String destFile, boolean sharpen, float sharpenLevel) throws IOException { sharpenMatrix = calculeSharpenMatrix(sharpenLevel); BufferedImage imageRGBSharpen = null; IIOImage iioImage = null; BufferedImage image = SwingFXUtils.fromFXImage(img, null); // Get buffered image. BufferedImage imageRGB = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.OPAQUE); // Remove alpha-channel from buffered image. Graphics2D graphics = imageRGB.createGraphics(); graphics.drawImage(image, 0, 0, null); if (sharpen) { imageRGBSharpen = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB); Kernel kernel = new Kernel(3, 3, sharpenMatrix); ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); cop.filter(imageRGB, imageRGBSharpen); } ImageWriter writer = null; FileImageOutputStream output = null; try { writer = ImageIO.getImageWritersByFormatName("bmp").next(); ImageWriteParam param = writer.getDefaultWriteParam(); output = new FileImageOutputStream(new File(destFile)); writer.setOutput(output); if (sharpen) { iioImage = new IIOImage(imageRGBSharpen, null, null); } else { iioImage = new IIOImage(imageRGB, null, null); } writer.write(null, iioImage, param); } catch (IOException ex) { throw ex; } finally { if (writer != null) { writer.dispose(); } if (output != null) { output.close(); } } graphics.dispose(); }
From source file:com.github.zhanhb.ckfinder.connector.utils.ImageUtils.java
/** * check if image size isn't bigger then biggest allowed. * * @param part servlet part/*from ww w.ja va 2 s .c o m*/ * @param context ckfinder context. * @return true if image size isn't bigger then biggest allowed. * @throws IOException when IO Exception occurs during reading image. */ public static boolean checkImageSize(InputStreamSource part, CKFinderContext context) throws IOException { ImageProperties image = context.getImage(); final int maxWidth = image.getMaxWidth(); final int maxHeight = image.getMaxHeight(); if (maxHeight == 0 && maxWidth == 0) { return true; } BufferedImage bi; try (InputStream stream = part.getInputStream()) { bi = ImageIO.read(stream); } if (bi != null) { log.debug("image size: {} {}", bi.getWidth(), bi.getHeight()); return (maxHeight == 0 || bi.getHeight() <= maxHeight) && (maxWidth == 0 || bi.getWidth() <= maxWidth); } return false; }
From source file:com.ckfinder.connector.utils.ImageUtils.java
/** * check if image size isn't bigger then bigest allowed. * * @param stream temp file input stream. * @param conf connector configuration.//from w w w. j a v a 2 s.co m * @return true if image size isn't bigger then bigest allowe. * @throws IOException when error occurs during reading image. */ public static boolean checkImageSize(final InputStream stream, final IConfiguration conf) throws IOException { BufferedImage bi = ImageIO.read(stream); stream.close(); if (bi == null) { return false; } if (bi.getHeight() > conf.getImgHeight() || bi.getWidth() > conf.getImgWidth()) { return false; } return true; }
From source file:editeurpanovisu.ReadWriteImage.java
/** * * @param img// w w w . j av a 2s. c om * @param destFile * @param quality * @param sharpen * @param sharpenLevel * @throws IOException */ public static void writeJpeg(Image img, String destFile, float quality, boolean sharpen, float sharpenLevel) throws IOException { sharpenMatrix = calculeSharpenMatrix(sharpenLevel); BufferedImage imageRGBSharpen = null; IIOImage iioImage = null; BufferedImage image = SwingFXUtils.fromFXImage(img, null); // Get buffered image. BufferedImage imageRGB = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.OPAQUE); // Remove alpha-channel from buffered image. Graphics2D graphics = imageRGB.createGraphics(); graphics.drawImage(image, 0, 0, null); if (sharpen) { imageRGBSharpen = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB); Kernel kernel = new Kernel(3, 3, sharpenMatrix); ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); cop.filter(imageRGB, imageRGBSharpen); } ImageWriter writer = null; FileImageOutputStream output = null; try { writer = ImageIO.getImageWritersByFormatName("jpeg").next(); ImageWriteParam param = writer.getDefaultWriteParam(); param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); param.setCompressionQuality(quality); output = new FileImageOutputStream(new File(destFile)); writer.setOutput(output); if (sharpen) { iioImage = new IIOImage(imageRGBSharpen, null, null); } else { iioImage = new IIOImage(imageRGB, null, null); } writer.write(null, iioImage, param); } catch (IOException ex) { throw ex; } finally { if (writer != null) { writer.dispose(); } if (output != null) { output.close(); } } graphics.dispose(); }
From source file:de.mprengemann.intellij.plugin.androidicons.util.ImageUtils.java
private static void verifyBorderImage(BufferedImage border) throws IOException { int[] rgb = border.getRGB(0, 0, border.getWidth(), border.getHeight(), null, 0, border.getWidth()); for (int aRgb : rgb) { if ((0xff000000 & aRgb) != 0) { if (aRgb != 0xff000000 && aRgb != 0xffff0000) { throw new IOException(); }/*from ww w .j a v a 2 s . c o m*/ } } }