|
Shrinking an image by skipping pixels |
|
|
The following Java method takes a BufferedImage object and returns its shrinked
version. The parameter n specifies the shrinking factor.
To shrink an image by an integer factor n, we will sample every nth pixel in
the horizontal and vertical dimensions and ignore the others.
public static BufferedImage enlarge(BufferedImage image, int n) {
int w = image.getWidth() / n;
int h = image.getHeight() / n;
BufferedImage shrunkImage =
new BufferedImage(w, h, image.getType());
for (int y=0; y < h; ++y)
for (int x=0; x < w; ++x)
shrunkImage.setRGB(x, y, image.getRGB(x*n, y*n));
return shrunkImage;
}
|
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.