用Java缩放图像

时间:2013-02-16 20:19:28

标签: java swing

我想使用以下java代码缩小图像。原始图像显示在屏幕上(高度大于maxHeight)。为什么呢?

try{

        final int maxHeight = 600;
        JLabel picLabel;
        BufferedImage myPicture = ImageIO.read(new File("src/VIZ/"+listOfFiles[1].getName()));
        int height = myPicture.getHeight();
        int width = myPicture.getWidth();
        if ( height < maxHeight ){
            int multiplier = height/maxHeight;
            height = maxHeight;
            int newWidth = width/multiplier;
            BufferedImage bi = new BufferedImage(newWidth, maxHeight, BufferedImage.TYPE_INT_ARGB);
            picLabel = new JLabel(new ImageIcon( bi ));
        }else{
        picLabel = new JLabel(new ImageIcon( myPicture ));
        }


        console.add(picLabel);
    }

    catch(Exception e){

    }

0 个答案:

没有答案