最邻点插值的Java实现

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/axman/article/details/75387141
BufferedImage src = ImageIO.read(new File("/Users/axman/Desktop/111.jpg"));
int w = src.getWidth();
int h = src.getHeight();
double scala = 1.5d;
int dw = (int)Math.round(w * scala);
int dh = (int)Math.round(h * scala);
BufferedImage dest = new BufferedImage(dw, dh, BufferedImage.TYPE_INT_RGB);
for (int i = 0; i != dw; ++i) {
    for (int j = 0; j != dh; ++j) {

        int x = (int)Math.round(i / scala);
        int y = (int)Math.round(j / scala);
        if (x < w && x >= 0 && y < h && y >= 0) {
            dest.setRGB(i, j, src.getRGB(x, y));
        }
    }
}
ImageIO.write(dest, "JPEG", new File("/Users/axman/Desktop/222.jpg"));

猜你喜欢

转载自blog.csdn.net/axman/article/details/75387141