views:

29

answers:

2

Is there a way to re-size a transparent image in windows mobile(C#)? I can re-size the image but I am losing the transparency. It is being replaced with white.

Here is what I have now

public static void ResizePicture(string imageFileName, Size maxSize)
{
    using (Image src = new Bitmap(imageFileName))
    {
        using (Bitmap dst = new Bitmap(maxSize.Width, maxSize.Height))
        {
            using (Graphics g = Graphics.FromImage(dst))
            {

                ImageAttributes imageAttr = new ImageAttributes();
                g.Clear(Color.Transparent);
                g.DrawImage(src, new Rectangle(0, 0, dst.Width, dst.Height), 0, 0, src.Width, src.Height, GraphicsUnit.Pixel, imageAttr);
            }
            dst.Save(imageFileName, ImageFormat.Png);
        }                
    }
}
+1  A: 

Have a look at this as found in the MSDN about setting the transparency color. It looks like you need to set the SetColorKey for this to work. See also here that explains you cannot set the transparency (apparently contradicting the first link). But, you can still down the Smart Devices Framework (community edition) found in OpenNetCF.org and use that instead to handle the transparency workaround. I would try the first link before going any further to see if that works.

Hope this helps, Best regards, Tom.

tommieb75
A: 

The CF has, in my opinion anyway, a bug. Graphics.Clear with Color.Transparent actually fills the image with white, not transparent. The workaround is tedious. See the link above.

ctacke