List of usage examples for java.awt.image BufferedImage getHeight
public int getHeight()
From source file:de.mprengemann.intellij.plugin.androidicons.images.ImageUtils.java
private static void verifyBorderImage(BufferedImage border) throws Wrong9PatchException { 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 Wrong9PatchException(); }// w ww.jav a2 s . c o m } } }
From source file:business.model.CaptchaModel.java
/** * * @param baseImage//from w w w.j a va 2 s. c o m * @return */ private static BufferedImage getDistortedImage(BufferedImage baseImage) { BufferedImage distortedImage = new BufferedImage(baseImage.getWidth(), baseImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graph = (Graphics2D) distortedImage.getGraphics(); ShadowFilter shadowFilter = new ShadowFilter(); shadowFilter.setRadius(10); shadowFilter.setDistance(5); shadowFilter.setOpacity(1); Random rand = new Random(); RippleFilter rippleFilter = new RippleFilter(); rippleFilter.setWaveType(RippleFilter.SINE); rippleFilter.setXAmplitude(1.6f); rippleFilter.setYAmplitude(1.0f); rippleFilter.setXWavelength(5); rippleFilter.setYWavelength(2); rippleFilter.setEdgeAction(TransformFilter.BILINEAR); BufferedImage effectImage = rippleFilter.filter(baseImage, null); effectImage = shadowFilter.filter(effectImage, null); graph.drawImage(effectImage, 0, 0, null, null); graph.dispose(); // draw lines over the image and/or text // noiseProducer.makeNoise(distortedImage, .1f, .1f, .25f, .25f); return distortedImage; }
From source file:com.oneis.utils.ImageColouring.java
/** * Transform the colours in an image.//w ww . j a va2 s. c o m * * @param Filename Full pathname to the source file * @param Method Which colouring method to use, use METHOD_* constants * @param Colours Array of 0xRRGGBB colours for recolouring * @param JPEGQuality If the image is a JPEG, the output quality for * reencoding * @param Output An OutputStream to write the file. Will be closed. */ static public void colourImage(String Filename, int Method, int[] Colours, int JPEGQuality, OutputStream Output) throws IOException { ColouringInfo colouringInfo = prepareForColouring(Method, Colours); String extension = Filename.substring(Filename.lastIndexOf('.') + 1, Filename.length()); String outputFormat = extension; if (outputFormat.equals("gif")) { if (!colourImageGIF(Filename, colouringInfo, Output)) { throw new RuntimeException("Failed to directly colour GIF file"); } return; } BufferedImage image = ImageIO.read(new File(Filename)); int width = image.getWidth(); int height = image.getHeight(); // Rewrite the pixels int[] pixelBuffer = new int[width]; for (int y = 0; y < height; ++y) { image.getRGB(0, y, width, 1, pixelBuffer, 0, width); doColouring(pixelBuffer, colouringInfo); image.setRGB(0, y, width, 1, pixelBuffer, 0, width); } // Writing is done the hard way to enable the JPEG quality to be set. // Get a writer Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(outputFormat); if (!iter.hasNext()) { throw new RuntimeException("Couldn't write image of type " + outputFormat); } ImageWriter writer = iter.next(); ImageWriteParam iwparam = null; // Is it JPEG? If so, might want to set the quality if (outputFormat.equals("jpeg") || outputFormat.equals("jpg")) { // Clamp value int q = JPEGQuality; if (q < 10) { q = 10; } if (q > 100) { q = 100; } JPEGImageWriteParam jparam = new JPEGImageWriteParam(null); jparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jparam.setCompressionQuality((float) (((float) q) / 100.0)); iwparam = jparam; } ImageOutputStream output = ImageIO.createImageOutputStream(Output); writer.setOutput(output); writer.write(null, new IIOImage(image, null, null), iwparam); output.close(); }
From source file:common.utils.ImageUtils.java
/** * * @param src images to draw, they must be resized to an appropriate size * @param dst image where given images will be drawen *//* www .ja v a 2 s .c om*/ public static void draw4on1(BufferedImage[] src, BufferedImage dst) { Graphics2D g2 = dst.createGraphics(); g2.setColor(java.awt.Color.WHITE); g2.fillRect(0, 0, dst.getWidth(), dst.getHeight()); int dxi; int dyi = 0; int x0 = dst.getWidth() - 5; int y0 = 5; int x = x0; int y = y0; for (int i = 0; i < src.length; i++) { if (i % 2 == 0) { dxi = -10; } else { dxi = 0; } //g2.draw3DRect(dx - 1 , dy-tmp_bi.getHeight() - 1, tmp_bi.getWidth() + 1 , tmp_bi.getHeight() + 1, true); g2.drawImage(src[i], x - src[i].getWidth() + dxi, y + dyi, null); g2.drawString("#" + i, x - src[i].getWidth() + dxi, y + dyi + 20); //g2.rotate(Math.toRadians(4)); y = y + src[i].getHeight() / 2; if (y > dst.getHeight() - src[i].getHeight()) { y = y0; if (dyi == 0) dyi = 10; else dyi = 0; if (x < src[i].getWidth()) { x = dst.getWidth(); } x = x - src[i].getWidth() / 2; } } g2.setColor(Color.gray); g2.drawRect(0, 0, dst.getWidth() - 1, dst.getHeight() - 1); g2.dispose(); }
From source file:com.ckfinder.connector.utils.ImageUtils.java
/** * Uploads image and if the image size is larger than maximum allowed it * resizes the image./*from ww w . j a va2 s . c o m*/ * * @param stream input stream. * @param file file name * @param fileName name of file * @param conf connector configuration * @throws IOException when error occurs. */ public static void createTmpThumb(final InputStream stream, final File file, final String fileName, final IConfiguration conf) throws IOException { BufferedInputStream bufferedIS = new BufferedInputStream(stream); bufferedIS.mark(Integer.MAX_VALUE); BufferedImage image = ImageIO.read(bufferedIS); if (image == null) { throw new IOException("Wrong file"); } Dimension dimension = createThumbDimension(image, conf.getImgWidth(), conf.getImgHeight()); if (image.getHeight() == dimension.height && image.getWidth() == dimension.width) { bufferedIS.reset(); writeUntouchedImage(bufferedIS, file); } else { resizeImage(image, dimension.width, dimension.height, conf.getImgQuality(), file); } stream.close(); }
From source file:com.reydentx.core.common.PhotoUtils.java
public static byte[] resizeImage(ByteArrayInputStream data, int img_width, int img_height, boolean isPNG) { BufferedImage originalImage; try {// ww w .j av a 2 s . c om originalImage = ImageIO.read(data); Dimension origDimentsion = new Dimension(originalImage.getWidth(), originalImage.getHeight()); Dimension fitDimentsion = new Dimension(img_width, img_height); // Dimension dimentsion = getScaledDimension(origDimentsion, fitDimentsion); Dimension dimentsion = fitDimentsion; if (origDimentsion.width != dimentsion.width || origDimentsion.height != dimentsion.height) { ByteArrayOutputStream outstream = new ByteArrayOutputStream(); BufferedImage resizedImage = Scalr.resize(originalImage, Scalr.Method.QUALITY, Scalr.Mode.FIT_EXACT, dimentsion.width, dimentsion.height, Scalr.OP_ANTIALIAS); if (isPNG) { ImageIO.write(resizedImage, "png", outstream); } else { ImageIO.write(resizedImage, "jpg", outstream); } return outstream.toByteArray(); } else { data.reset(); ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); byte[] read = new byte[2048]; int i = 0; while ((i = data.read(read)) > 0) { byteArray.write(read, 0, i); } data.close(); return byteArray.toByteArray(); } } catch (Exception ex) { } return null; }
From source file:com.t3.image.ImageUtil.java
/** * Flip the image and return a new image * @param direction 0-nothing, 1-horizontal, 2-vertical, 3-both * @return/* w w w .j a va 2 s . c o m*/ */ public static BufferedImage flip(BufferedImage image, int direction) { BufferedImage workImage = new BufferedImage(image.getWidth(), image.getHeight(), image.getTransparency()); boolean flipHorizontal = (direction & 1) == 1; boolean flipVertical = (direction & 2) == 2; int workW = image.getWidth() * (flipHorizontal ? -1 : 1); int workH = image.getHeight() * (flipVertical ? -1 : 1); int workX = flipHorizontal ? image.getWidth() : 0; int workY = flipVertical ? image.getHeight() : 0; Graphics2D wig = workImage.createGraphics(); wig.drawImage(image, workX, workY, workW, workH, null); wig.dispose(); return workImage; }
From source file:com.alvermont.terraj.stargen.ui.UIUtils.java
/** * Build a list of label objects from a list of planets * * @param planets The list of planets to build labels for * @throws java.io.IOException If there is an error building the labels * @return A list of <code>JLabel</code> objects in the same order as the * input list//from ww w . j a va 2s.c o m */ public static List<JLabel> buildImages(List<Planet> planets) throws IOException { List<JLabel> labels = new ArrayList<JLabel>(); List<BufferedImage> images = getPlanetImages(planets); Planet p = planets.get(0); for (BufferedImage bi : images) { ImageIcon icon = new ImageIcon(bi); JLabel label = new JLabel(icon); label.setPreferredSize(new Dimension(bi.getWidth(), bi.getHeight())); label.setMinimumSize(new Dimension(bi.getWidth(), bi.getHeight())); label.setToolTipText("<html>" + UIUtils.getInfo(p) + "</html>"); labels.add(label); log.debug("Added icon for planet " + p.getNumber() + " size " + bi.getWidth() + "," + bi.getHeight()); p = p.getNextPlanet(); } return labels; }
From source file:com.afis.jx.ckfinder.connector.utils.ImageUtils.java
/** * create thumb file./*from w w w .jav a 2s. c om*/ * * @param orginFile origin image file. * @param file file to save thumb * @param conf connector configuration * @throws IOException when error occurs. */ public static void createThumb(final File orginFile, final File file, final IConfiguration conf) throws IOException { BufferedImage image = ImageIO.read(orginFile); if (image != null) { Dimension dimension = createThumbDimension(image, conf.getMaxThumbWidth(), conf.getMaxThumbHeight()); FileUtils.createPath(file, true); if (image.getHeight() == dimension.height && image.getWidth() == dimension.width) { writeUntouchedImage(orginFile, file); } else { resizeImage(image, dimension.width, dimension.height, conf.getThumbsQuality(), file); } } else { if (conf.isDebugMode()) { throw new IOException("Wrong image file"); } } }
From source file:de.mprengemann.intellij.plugin.androidicons.util.ImageUtils.java
private static BufferedImage resizeNormalImage(BufferedImage image, ImageInformation information) throws IOException { int newWidth = image.getWidth(); int newHeight = image.getHeight(); if (MathUtils.floatEquals(information.getFactor(), 1f)) { return image; }//from w w w. j a v a 2 s. c o m if (information.getFactor() >= 0) { newWidth = (int) (newWidth * information.getFactor()); newHeight = (int) (newHeight * information.getFactor()); } BufferedImage resizedImage = null; switch (information.getAlgorithm()) { case SCALR: Scalr.Method scalrMethod = (Scalr.Method) information.getMethod(); resizedImage = Scalr.resize(image, scalrMethod, newWidth, newHeight, Scalr.OP_ANTIALIAS); break; case THUMBNAILATOR: return Thumbnails.of(image).size(newWidth, newHeight).asBufferedImage(); } return resizedImage; }