最邻点插值的Java实现

来源:互联网 发布:2015年美工电脑配置 编辑:程序博客网 时间:2024/05/22 18:14
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"));
原创粉丝点击