Skip to content

Instantly share code, notes, and snippets.

@SavvasStephanides
Created December 13, 2013 17:03
Show Gist options
  • Save SavvasStephanides/7947508 to your computer and use it in GitHub Desktop.
Save SavvasStephanides/7947508 to your computer and use it in GitHub Desktop.
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 Pixelation
{
public BufferedImage pixelateImage(File inputFile, int boxSize) throws IOException
{
BufferedImage bufferedImage = ImageIO.read(inputFile);
for(int w = 0 ; w < bufferedImage.getWidth() ; w+=boxSize)
{
for(int h = 0 ; h < bufferedImage.getHeight() ; h+=boxSize)
{
Color color = new Color(bufferedImage.getRGB(w, h));
Graphics imageGraphics = bufferedImage.getGraphics();
imageGraphics.setColor(color);
imageGraphics.fillRect(w, h, boxSize, boxSize);
}
}
return bufferedImage;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment