1

我想使用以下 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){

    }
4

0 回答 0