2011-07-27 19 views
5

可能性の重複を保持:
Merging two images in C#/.NET透明性を有する2枚のPNG画像をマージし、透明性を

Iは、2枚のPNG形式の画像を有し、両方は透明性が定義されています。これらをまとめて新しいPNG画像にする必要がありますが、結果の透明性を失うことはありません。最初のイメージをメインイメージと考え、2番目のイメージは追加/編集/削除インジケータなどのオーバーレイを追加するために使用されます。私は、メイン画像とオーバーレイのセットをとり、それらを組み合わせた出力画像の結果セットを生成する小さなユーティリティを作成しようとしています。

は、PHPのためのソリューションが、C#/

残念ながらあなたはピクセルを取得する方法あなたが言及していない
+2

可能な複製:http://stackoverflow.com/q/465172/15667。 これが役立つかどうかを確認してください。 – xan

+0

WinForms、ASP.NetまたはWPF? –

答えて

17

これは動作するはずです。

Bitmap source1; // your source images - assuming they're the same size 
Bitmap source2; 
var target = new Bitmap(source1.Width, source1.Height, PixelFormat.Format32bppArgb); 
var graphics = Graphics.FromImage(target); 
graphics.CompositingMode = CompositingMode.SourceOver; // this is the default, but just to be clear 

graphics.DrawImage(source1, 0, 0); 
graphics.DrawImage(source2, 0, 0); 

target.Save("filename.png", ImageFormat.Png); 
+0

ありがとう、これは私のために働いた! –

1

ため何も答えの多くがあるように思われる

ので、Pコード:

// The result will have its alpha chanell from "first", 
// the color channells from "second". 

assert (first.width = second.width) 
assert (first.height = second.height) 

for y in 0..height 
    for x in 0..width 
     RGBA col_first = first(x,y) 
     RGBA col_second = second(x,y) 

     result(x,y) = RGBA(col_second.r, 
          col_second.g, 
          col_second.b, 
          col_first.a ))