• category: swing folder: AnimatedGif title: Animated GIFでのコマ描画時処理 tags: [JLabel, Animation] author: aterai pubdate: 2007-05-14T19:32:29+09:00 description: JLabelなどで使用できるAnimated GIFファイルをテストします。 image: https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTHnR-lE1I/AAAAAAAAARc/gDDOKXhD7hQ/s800/AnimatedGif.png

概要

JLabelなどで使用できるAnimated GIFファイルをテストします。

サンプルコード

JLabel label1 = new JLabel("何もしない",
  new ImageIcon(getClass().getResource("no_disposal_specified.gif")),
  SwingConstants.LEFT);
JLabel label2 = new JLabel("そのまま残す",
  new ImageIcon(getClass().getResource("do_not_dispose.gif")),
  SwingConstants.LEFT);
JLabel label3 = new JLabel("背景色でつぶす",
  new ImageIcon(getClass().getResource("restore_to_background_color.gif")),
  SwingConstants.LEFT);
JLabel label4 = new JLabel("直前の画像に戻す",
  new ImageIcon(getClass().getResource("restore_to_previous.gif")),
  SwingConstants.LEFT);
View in GitHub: Java, Kotlin

解説

Animated GIFで、次のコマを描画する時、直前の画像を異なる方法で消去するAnimated GIFファイルを作成し、これらをJLabelに貼り付けてアニメーションをテストしています。上記のように透過色を使用する場合、Swingでは、3番目の「背景色でつぶす」にしておかないと残像が出てしまうようです。

  • 何もしない

    No disposal specified. The decoder is not required to take any action.

  • そのまま残す

    Do not dispose. The graphic is to be left in place.

  • 背景色でつぶす

    Restore to background color. The area used by the graphic must be restored to the background color.

  • 直前の画像に戻す

    Restore to previous. The decoder is required to restore the area overwritten by the graphic with what was there prior to rendering the graphic.

参考リンク

コメント