最邻点插值的Java实现

Posted axman

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了最邻点插值的Java实现相关的知识,希望对你有一定的参考价值。

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"));

以上是关于最邻点插值的Java实现的主要内容,如果未能解决你的问题,请参考以下文章