Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have two BufferedImages I loaded in from pngs. The first contains an image, the second an alpha mask for the image.

I want to create a combined image from the two, by applying the alpha mask. My google-fu fails me.

I know how to load/save the images, I just need the bit where I go from two BufferedImages to one BufferedImage with the right alpha channel.

the language C#
Sergey Alexandrovich Kryukov 19-Aug-11 23:16pm    
Tag it! WPF, Forms, what?! The answer totally depends on UI library you use. In both cases, it's relatively simple.

1 solution

Short answer: for System.Drawing (with System.Windows.Forms use System.Drawing.Bitmap.LockBits and System.Runtime.InteropServices.Marshal.Copy, see[^] with the code samples. Use System.Drawing.Imaging.PixelFormat which supports Alpha channel for output file.

For WPF, use System.Windows.Media.Imaging.BitmapImage for inputs, System.Windows.Media.Imaging.WriteableBitmap for output, see:[^],[^].

Always tag the UI library you want to use in your question.

Share this answer
BillWoodruff 20-Aug-11 4:02am    
Excellent answer, +5
Sergey Alexandrovich Kryukov 20-Aug-11 23:13pm    
Thank you, Bill.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900