Created
February 11, 2014 14:54
-
-
Save SavvasStephanides/8936308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.Graphics; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import javax.imageio.ImageIO; | |
public class Pixelate | |
{ | |
public void pixelateFile(int pixelSize, File inputFile, File outputFile) throws IOException | |
{ | |
// get a BufferedImage object from file | |
BufferedImage bufferedImage = ImageIO.read(inputFile); | |
// loop through the image and produce squares pixelSize*pixelSize | |
for(int w = 0 ; w < bufferedImage.getWidth() ; w+=pixelSize) | |
{ | |
for(int h = 0 ; h < bufferedImage.getHeight() ; h+=pixelSize) | |
{ | |
Color pixelColor = new Color(bufferedImage.getRGB(w, h)); | |
Graphics graphics = bufferedImage.getGraphics(); | |
graphics.setColor(pixelColor); | |
graphics.fillRect(w, h, pixelSize, pixelSize); | |
} | |
} | |
// output file | |
ImageIO.write(bufferedImage, "jpg", outputFile); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment