locked
Support for transparent png in WM 6.x RRS feed

  • Question

  • Is there support for transparent png in WM 6.x?

    I am developing an application that uses transparent png quite heavily, I could manage quite well in WM 5 but it is not working in WM6. In WM6 the transparent part shows as white.

    If there is no support, then what is the best way to handle transparency for an image? (eg. in S60 Symbian, combination of color bmp + mask, or svg format can be used).

    Thanks in advanced.
    Friday, April 24, 2009 8:36 AM

Answers

  • Hi Juan Noguera,

    before using below method  you have to make Image that area you want to transparent with dark color. then you are able to use below method, and this will working with managed code.

    example to see Image Click this link

    example image will shown as back color as dark color and HELLO will printing on your paint method as a transparent.

    Managed code for made image as transparent.


    private void MakeImgTransparent()
            {
                Graphics grx = null;
                try
                {
    
                    Bitmap objBmp = LoadYourImageAsBitmapobject();
                    Rectangle destRect = new Rectangle(0, 0, 50, 50);
                    grx = Graphics.FromImage(objBmp);
                    ImageAttributes attr = new ImageAttributes();
                    Color transparencyColor = objBmp.GetPixel(0, 0);
    
                    attr.SetColorKey(transparencyColor, transparencyColor);// Set the transparency color.
    
                    // Draw the image using the image attributes.
                    grx.DrawImage(objBmp, destRect, 0, 0, objBmp.Width, objBmp.Height, GraphicsUnit.Pixel, attr);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
                finally
                {
                    grx.Dispose();
                }
            }



    Hope this may be help...







    Pavan Pareta | If you find my post is helpful for you then mark as a answer.
    • Proposed as answer by WmDev Friday, April 24, 2009 8:44 PM
    • Marked as answer by Guang-Ming Bian - MSFT Thursday, April 30, 2009 5:39 AM
    Friday, April 24, 2009 8:44 PM

All replies

  • How are you loading and displaying the PNG? I'm using the imaging objects with great success on both platforms. See my blog for more info.

    João Paulo Figueira (Device Application Development MVP)
    Friday, April 24, 2009 10:13 AM
  • Hi Juan Noguera,

    Please refer the following links for transparent images support with Windows Mobile.

    http://johan.andersson.net/blog/2007/10/solution-for-transparent-images-on.html

    http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/eb66b1b3-8e13-42af-b659-c49b41bc2194


    Third party control:
    http://www.mobiletopsoft.com/pocket-pc/download-source-code-transparent-image-button-1-0.html


    Please let us know if you are looking for something different than this.

    Regards,
    Malleswar
    Friday, April 24, 2009 10:26 AM
  • Thanks Malleswar,

    I tried your solutions before sending this post, but it does not work with Framework 3.5. , and could not figure out a way to adapt it.
    Friday, April 24, 2009 11:35 AM
  • Joao,

    I am using the solution in:

    http://code.msdn.microsoft.com/iPhoneUI

    but it does not work too well in my case. It uses ImageAttribute class to define the transparency mask based on pixel [0,0] of the image.
    I.e. the color of pixel [0,0] is the one that will be used to decide which pixels in the image will be transparent.

    I use this on an image that has pink as color to be transparent. The result I get is that image is transparent on the outside, but has  a pink line on borders of non-transparent pixels.
    Friday, April 24, 2009 11:51 AM
  • Hi Juan Noguera,

    before using below method  you have to make Image that area you want to transparent with dark color. then you are able to use below method, and this will working with managed code.

    example to see Image Click this link

    example image will shown as back color as dark color and HELLO will printing on your paint method as a transparent.

    Managed code for made image as transparent.


    private void MakeImgTransparent()
            {
                Graphics grx = null;
                try
                {
    
                    Bitmap objBmp = LoadYourImageAsBitmapobject();
                    Rectangle destRect = new Rectangle(0, 0, 50, 50);
                    grx = Graphics.FromImage(objBmp);
                    ImageAttributes attr = new ImageAttributes();
                    Color transparencyColor = objBmp.GetPixel(0, 0);
    
                    attr.SetColorKey(transparencyColor, transparencyColor);// Set the transparency color.
    
                    // Draw the image using the image attributes.
                    grx.DrawImage(objBmp, destRect, 0, 0, objBmp.Width, objBmp.Height, GraphicsUnit.Pixel, attr);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
                finally
                {
                    grx.Dispose();
                }
            }



    Hope this may be help...







    Pavan Pareta | If you find my post is helpful for you then mark as a answer.
    • Proposed as answer by WmDev Friday, April 24, 2009 8:44 PM
    • Marked as answer by Guang-Ming Bian - MSFT Thursday, April 30, 2009 5:39 AM
    Friday, April 24, 2009 8:44 PM