开发者

Resize transparent images in windows mobile using C#

开发者 https://www.devze.com 2022-12-18 08:51 出处:网络
Is there a way to re-size a transparent image in windows开发者_Python百科 mobile(C#)? I can re-size the image but I am losing the transparency. It is being replaced with white.

Is there a way to re-size a transparent image in windows开发者_Python百科 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);
        }                
    }
}


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号