none
Alpha channel transparency for bitmap images RRS feed

  • Question

  • Hi,

     

    We have several bitmap images that need to be moved from WinForms based code to WPF based code. However, I need help in figuring out how to force the default Alpha channel to become transparent. If you recall, in WinForms, all you need to do is call MakeTransparent() on the bitmap image. What exactly is the equivalent in WPF world?

     

    Also, I came across one thread that said that .bmp images are not supported for Alpha blending and that one must use .png images. Is this information correct?

     

    Thank you in advance for your help.

     

    Regards,

    Peter

     

    Wednesday, December 26, 2007 6:34 AM

Answers

  •  Peter wrote:

    We have several bitmap images that need to be moved from WinForms based code to WPF based code. However, I need help in figuring out how to force the default Alpha channel to become transparent. If you recall, in WinForms, all you need to do is call MakeTransparent() on the bitmap image. What exactly is the equivalent in WPF world?


    WPF doesn't have the MakeTransparent equivalent, you can first off make the bitmap transparent using GDI+, and feeds it to WPF using Imaging.CreateBitmapSourceFromHBitmap() method as followings:
    Bitmap bitmap = new Bitmap("filename");
    bitmap.MakeTransparent();
    Imaging.CreateBitmapSourceFromHBitmap(
    bitmap.GetHbitmap(),
    IntPtr.Zero,
    Int32Rect.Empty,
    BitmapSizeOptions.FromEmptyOptions());

     Peter wrote:

    Also, I
    came across one thread that said that .bmp images are not supported for
    Alpha blending and that one must use .png images. Is this information
    correct?



    Yes, png images supports alpha channel which is what WPF "prefers".

    Hope this helps


    Friday, December 28, 2007 5:05 AM