Dev-Picayune

picayune: of little value or importance

C# and PNG

Last night I learned about .net’s somewhat imperfect support for PNG (Portable Network Graphics). As an interesting exercise, you can specify a semi-transparent PNG (pronounced PING) as the background image for a window. Run the program and you should see right through part of the window… which would be a really cool side effect. Unfortunately, the bit you see stays with the window as you subsequently move it. To get around this “feature”, I found by trial and error that you should not specify the background image at the window. You should create a Panel that fills the window and specify the background image for the panel and set the panel’s background color to transparent. This achieves the desired effect of having a semi-transparent image over window (thus preserving the native color set specified by the user within windows).

It also appears (after reading some articles — sorry I lost the links) that Longhorn’s native API (WinFX) will natively support opacity (or transparency depending on how you look at it) setting for all controls. This would be really cool since you could then vary the opacity of objects on the window to achieve an anti-aliased effect without much effort. Also of note, Microsoft is planning on including the C# compiler with the operating system. Not just the PRO version of the operating system but ALL versions of the operating system. Definitely a UNIX like move really. All this ties back to the use of XAML to define windows and resources and events, etc… for programs. Also related, wxWindows will support the alpha-transparency information in .PNG files starting with version 2.5. Currently wxPython appears to be 2.4 based. I may need to wait for that version before doing my updated CPU monitor program. The one thing I really want though for wxWindows is a way to do opacity setting for the window as a whole. I haven’t found any code for that at all. I am sure, though that I might could do it using some win32 api calls. Finally, a chance to do something that other people have not necessarily written about.

2 comments

2 Comments so far

  1. KUF April 25th, 2007 5:28 pm

    I am sure you know this by now but the C# compiler has always been provided with the .NET Framework. It gets installed as an executable called csc.exe and you can call it in code as well, to do on-the-fly code compilation. Indeed, there is a VB.NET compiler as well called vbc.exe which does the same thing.

  2. KUF April 25th, 2007 5:30 pm

    To add to the above, the Windows Vista SDK adds a new compiler called wfc.exe which compiles *.xoml files, which are declarative workflow files.

Leave a reply