独自にアルファブレンドした色を作りたいけど、それらしい API が Java の標準ライブラリに見つからないので作ってみた。
// アルファブレンディング
private static Color getAlphaBlendedColor(Color background, Color foreground, float alpha){
int br = background.getRed();
int bg = background.getGreen();
int bb = background.getBlue();
int fr = foreground.getRed();
int fg = foreground.getGreen();
int fb = foreground.getBlue();
// Value = Value0(1.0 - Alpha) + Value1(Alpha)
int newr = (int)((br * (1.0 - alpha)) + (fr * alpha));
int newg = (int)((bg * (1.0 - alpha)) + (fg * alpha));
int newb = (int)((bb * (1.0 - alpha)) + (fb * alpha));
return new Color(newr, newg, newb);
}
Refs. Alpha compositing - Wikipedia, the free encyclopedia, アルファブレンド - Wikipedia
tags: zlashdot Java Java
Posted by NI-Lab. (@nilab)