• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:RGBImageFilterでアイコンの色調を変更
#navi(../)
*RGBImageFilterでアイコンの色調を変更 [#w9fce2db]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2006-08-21~
更新日:&lastmod;
Posted by [[terai]] at 2006-08-21

#contents

**概要 [#l9857d29]
RGBImageFilterで色調を変更したアイコンの用意し、評価用コンポーネントを作成します。

-&jnlp;
-&jar;
-&zip;

#screenshot

**サンプルコード [#a85a2963]
#code{{
 private final ImageProducer ip = orgIcon.getImage().getSource();
 private MyLabel makeLabel(float[] filter) {
   SelectedImageFilter sif = new SelectedImageFilter(filter);
   ImageIcon imageIcon = new ImageIcon(
     createImage(new FilteredImageSource(ip, sif)));
   return new MyLabel(imageIcon);
 }
 private class SelectedImageFilter extends RGBImageFilter {
   private final float[] filter;
   public SelectedImageFilter(float[] filter) {
     this.filter = filter;
     canFilterIndexColorModel = true;
   }
   public int filterRGB(int x, int y, int argb) {
     Color color = new Color(argb, true);
     float[] array = new float[4];
     color.getComponents(array);
     return new Color(array[0]*filter[0],
                      array[1]*filter[1],
                      array[2]*filter[2],
                      array[3]).getRGB();
   }
 }
private final ImageProducer ip = orgIcon.getImage().getSource();
private MyLabel makeLabel(float[] filter) {
  SelectedImageFilter sif = new SelectedImageFilter(filter);
  ImageIcon imageIcon = new ImageIcon(
    createImage(new FilteredImageSource(ip, sif)));
  return new MyLabel(imageIcon);
}
private class SelectedImageFilter extends RGBImageFilter {
  private final float[] filter;
  public SelectedImageFilter(float[] filter) {
    this.filter = filter;
    canFilterIndexColorModel = true;
  }
  public int filterRGB(int x, int y, int argb) {
    Color color = new Color(argb, true);
    float[] array = new float[4];
    color.getComponents(array);
    return new Color(array[0]*filter[0],
                     array[1]*filter[1],
                     array[2]*filter[2],
                     array[3]).getRGB();
  }
}
}}
-&jnlp;
-&jar;
-&zip;

**解説 [#s11c2ccf]
RGBImageFilterを使用して、一つのアイコンから複数の色の異なるアイコンを生成しています。

上記のサンプルは、アマゾンなど((いろんな所でよく見かけるのですが、オリジナルは何処なんでしょうか?))でよく見かける5段階の評価を行うコンポーネントです。クリックしたアイコンの位置が評価レベルになります。

**参考リンク [#s1cec87d]
-[[XP Style Icons - Windows Application Icon, Software XP Icons>http://www.icongalore.com/]]
--アイコンを利用しています。

**コメント [#afaf0ed0]
- 「Rating Bar」と言うみたいです。[[Masuga Design » Unobtrusive AJAX Star Rating Bar>http://www.masugadesign.com/the-lab/scripts/unobtrusive-ajax-star-rating-bar/]] -- [[terai]] &new{2006-11-07 (火) 12:38:34};

#comment
素晴しい!:)