Mega Code Archive

 
Categories / Java / Advanced Graphics
 

Enlarging an image by pixel replication

import java.awt.image.BufferedImage; public class Main {   public static void main(String[] argv) throws Exception {   }   public static BufferedImage enlarge(BufferedImage image, int n) {     int w = n * image.getWidth();     int h = n * image.getHeight();     BufferedImage enlargedImage = new BufferedImage(w, h, image.getType());     for (int y = 0; y < h; ++y){       for (int x = 0; x < w; ++x){         enlargedImage.setRGB(x, y, image.getRGB(x / n, y / n));       }     }     return enlargedImage;   } }