繁体   English   中英

调整具有gif格式的imageIcon的大小

[英]resizing an imageIcon that has a gif format

我在这里尝试做两件事:1.我的代码中有一个imageIcon(称为dice),当您按下它时,它会变为移动的imageIcon(称为dice2)。 但是我无法调整运动imageIcon 2的大小。为dice2设置计时器,并且在完成时显示“ dice”

到目前为止,这是我的代码

  ImageIcon dice = new ImageIcon("dice.png") ;
  Image image = dice.getImage(); // transform it 
  Image newimg = image.getScaledInstance(150, 120,java.awt.Image.SCALE_SMOOTH); // scale it the smooth way  
  dice = new ImageIcon(newimg) ;
  dice_1 = new JButton(dice);           
  dice_1.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
          dicePanel.remove(dice_1);
          dicePanel.revalidate();
          dicePanel.repaint();                
          ImageIcon dice2 = new ImageIcon("dice.gif");
          dice_1 = new JButton(dice2);
          dice_1.setOpaque(false);
          dice_1.setContentAreaFilled(false);
          dice_1.setBorderPainted(false);
          dicePanel.add(dice_1);  
          // random number 
          Random r = new Random();
          R = r.nextInt(10) + 2;
          randomNumbe.setText("تقدم " + R + " خطوة");
      }
  });

同时支持SCALE_SMOOTH和SCALE_AREA_AVERAGING的面积平均算法似乎不适用于动画GIF。 使用它时,结果是空白图像。

SCALE_DEFAULT效果很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM