List of usage examples for java.awt.image ConvolveOp ConvolveOp
public ConvolveOp(Kernel kernel, int edgeCondition, RenderingHints hints)
From source file:rega.genotype.ui.util.GenotypeLib.java
public static void scalePNG(File in, File out, double perc) throws IOException { Image i = ImageIO.read(in); Image resizedImage = null;//from w ww. jav a 2 s .co m int newWidth = (int) (i.getWidth(null) * perc / 100.0); int newHeight = (int) (i.getHeight(null) * perc / 100.0); resizedImage = i.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH); // This code ensures that all the pixels in the image are loaded. Image temp = new ImageIcon(resizedImage).getImage(); // Create the buffered image. BufferedImage bufferedImage = new BufferedImage(temp.getWidth(null), temp.getHeight(null), BufferedImage.TYPE_INT_RGB); // Copy image to buffered image. Graphics g = bufferedImage.createGraphics(); // Clear background and paint the image. g.setColor(Color.white); g.fillRect(0, 0, temp.getWidth(null), temp.getHeight(null)); g.drawImage(temp, 0, 0, null); g.dispose(); // Soften. float softenFactor = 0.05f; float[] softenArray = { 0, softenFactor, 0, softenFactor, 1 - (softenFactor * 4), softenFactor, 0, softenFactor, 0 }; Kernel kernel = new Kernel(3, 3, softenArray); ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); bufferedImage = cOp.filter(bufferedImage, null); ImageIO.write(bufferedImage, "png", out); }