|
Enlarging an image by pixel replication |
|
|
The following Java method takes a BufferedImage object and returns its enlarged
version. The parameter n specifies the enlargement factor.
To enlarge an image by an integer factor n, we will replicate pixels such that
each pixel in the input image becomes an n x n block of identical pixels
in the output image.
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;
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.