Click here to Skip to main content
15,949,686 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#
Posted
Comments
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.
--SA

1 solution

Short answer: for System.Drawing (with System.Windows.Forms use System.Drawing.Bitmap.LockBits and System.Runtime.InteropServices.Marshal.Copy, see http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[^] 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:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx[^].

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

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

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