« Papervision3D でテクスチャぐるぐる PlaneWorld サンプル その2 by Flex SDK | メイン | Java のフィルタ行列APIを使っていろいろな画像処理をしてみた »

2007年05月19日

Java で独自にアルファブレンドする

独自にアルファブレンドした色を作りたいけど、それらしい 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

投稿者 NI-Lab. : 2007年05月19日 15:02

Please post your comments -> Ido-Batarian BBS
コメントはこちらの Ido-Batarian BBS へどうぞ。

« Papervision3D でテクスチャぐるぐる PlaneWorld サンプル その2 by Flex SDK | メイン | Java のフィルタ行列APIを使っていろいろな画像処理をしてみた »

人気ブログランキング - NI-Lab.'s ヅラッシュドット [Valid RSS]