Swing/RatingLabel のバックアップの現在との差分(No.13)
-
category: swing
folder: RatingLabel
title: RGBImageFilterでアイコンの色調を変更
tags: [ImageIcon, RGBImageFilter, JLabel]
author: aterai
pubdate: 2006-08-21T11:55:27+09:00
description: RGBImageFilterで色調を変更したアイコンの用意し、評価用コンポーネントを作成します。
image:
hreflang:
href: https://java-swing-tips.blogspot.com/2008/12/jlabel-star-rating-bar.html lang: en
概要
概要
RGBImageFilter
で色調を変更したアイコンの用意し、評価用コンポーネントを作成します。
Screenshot
Advertisement
サンプルコード
サンプルコード
private final ImageProducer ip = orgIcon.getImage().getSource();
#spandel
private ImageIcon makeStarImageIcon(float[] filter) {
#spanend
SelectedImageFilter sif = new SelectedImageFilter(filter);
return new ImageIcon(
createImage(new FilteredImageSource(ip, sif)));
#spanadd
#spanend
#spanadd
private static ImageIcon makeStarImageIcon(
#spanend
ImageProducer ip, float rf, float gf, float bf) {
return new ImageIcon(Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(ip, new SelectedImageFilter(rf, gf, bf))));
}
#spandel
private class SelectedImageFilter extends RGBImageFilter {
#spanend
private final float[] filter;
public SelectedImageFilter(float[] arrays) {
filter = new float[arrays.length];
System.arraycopy(arrays, 0, filter, 0, arrays.length);
#spanadd
#spanend
#spanadd
class SelectedImageFilter extends RGBImageFilter {
#spanend
private final float rf;
private final float gf;
private final float bf;
#spanadd
#spanend
protected SelectedImageFilter(float rf, float gf, float bf) {
super();
this.rf = Math.min(1f, rf);
this.gf = Math.min(1f, gf);
this.bf = Math.min(1f, bf);
canFilterIndexColorModel = false;
}
#spanadd
#spanend
@Override public int filterRGB(int x, int y, int argb) {
int r = (int)(((argb >> 16) & 0xff) * filter[0]);
int g = (int)(((argb >> 8) & 0xff) * filter[1]);
int b = (int)(((argb ) & 0xff) * filter[2]);
return (argb & 0xff000000) | (r<<16) | (g<<8) | (b);
int r = (int) (((argb >> 16) & 0xFF) * rf);
int g = (int) (((argb >> 8) & 0xFF) * gf);
int b = (int) ((argb & 0xFF) * bf);
return (argb & 0xFF_00_00_00) | (r << 16) | (g << 8) | (b);
}
}
View in GitHub: Java, Kotlin解説
上記のサンプルは、RGBImageFilter
を使用して、一つのアイコンから複数の色の異なるアイコンを生成し、5
段階の評価を行うコンポーネントを作成しています。クリックしたアイコンの位置が評価レベルになります。
解説
上記のサンプルはRGBImageFilter
を使用して1
つのアイコンから複数の色の異なるアイコンを生成し、5
段階の評価を行うコンポーネントを作成しています。クリックしたアイコンの位置が評価レベルになります。
参考リンク
参考リンク
- PI Diagona Icons Pack 1.0 - Download Royalty Free Icons and Stock Images For Web & Graphics Design
- アイコンを利用しています。
- アイコンを引用