通过插值方法生成高清缩略图代码

package com;



import java.awt.image.BufferedImage;

import java.io.File;



import javax.imageio.ImageIO;



public class Lanczos {

    private static final double WORK_LOAD_FACTOR = 0.265;



    private static final double LANCZOS_SUPPORT = 3;

    private static final double LANCZOS_WINDOW = 3;

    private static final double LANCZOS_SCALE = 1;

    private static final double LANCZOS_BLUR = 1;



    private static final double EPSILON = 1.0e-6;



    private static class ContributionInfo {

        private double weight;

        private int pixel;

    }



    public static BufferedImage resizeImage(BufferedImage image, double ratio) {

        return resizeImage(image, (int)(image.getWidth() * ratio + 0.5), (int)(image.getHeight() * ratio + 0.5));        

    }



    public static BufferedImage resizeImage(BufferedImage image, double xRatio, double yRatio) {

        return resizeImage(image, (int)(image.getWidth() * xRatio + 0.5), (int)(image.getHeight() * yRatio + 0.5));        

    }



    public static BufferedImage resizeImage(BufferedImage image, int width, int height) {

        double xFactor = width * 1.0 / image.getWidth();

        double yFactor = height * 1.0 / image.getHeight();



        BufferedImage resizeImage = new BufferedImage(width, height, image.getType());

        BufferedImage filterImage = null;



        if (xFactor * yFactor > WORK_LOAD_FACTOR) {

            filterImage = new BufferedImage(width, image.getHeight(), image.getType());

            horizontalFilter(image, filterImage, xFactor);

            verticalFilter(filterImage, resizeImage, yFactor);

        } else {

            filterImage = new BufferedImage(image.getWidth(), height, image.getType());

            verticalFilter(image, filterImage, yFactor);

            horizontalFilter(filterImage, resizeImage, xFactor);

        }

        return resizeImage;

    }



    private static void verticalFilter(BufferedImage image, BufferedImage resizeImage,

            double yFactor) {

        double scale = Math.max(1.0 / yFactor, 1.0);

        double support = scale * LANCZOS_SUPPORT;

        if (support > 16) & 0xFF);

                    green += alpha * ((rgb >>[img]/images/smiles/icon_cool.gif" alt="[/img]
 & 0xFF);

                    blue += alpha * (rgb & 0xFF);

                }

                int rgb = roundToQuantum(red) > 16) & 0xFF);

                    green += alpha * ((rgb >>[img]/images/smiles/icon_cool.gif" alt="[/img]
 & 0xFF);

                    blue += alpha * (rgb & 0xFF);

                }

                int rgb = roundToQuantum(red) = 255)

            return 255;

        return (int) (value + 0.5);

    }



    public static void main(String[] args) throws Exception {

        BufferedImage image = ImageIO.read(new File("C:/Program Files/SuperMap/精细化农业气候区划产品制作系统/Bin/Product/广西壮族自治区/广西荔枝/广西荔枝/20101028/广西壮族自治区_广西荔枝_广西荔枝_20101028.bmp"));

        ImageIO.write(resizeImage(image, 670, 420), "PNG", new File("C:/Program Files/SuperMap/精细化农业气候区划产品制作系统/Bin/Product/广西壮族自治区/广西荔枝/广西荔枝/20101028/广西壮族自治区_广西荔枝_广西荔枝_20101028_testr.bmp"));

    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值