June 27th, 2010

15 minute blog post: PNG files in Packages

Recently I’ve been helping plan the next version of Visual Studio. It’s way too early to be talking about specifics, but one topic came up this week that I have to share.

Package Authoring

As some of you may have noticed, many of the regular posters here have been busy writing extensions for the Visual Studio Gallery, some of which have been featured on this blog. You too can create extensions for Visual Studio 2010 using the Visual Studio SDK. If you’ve ever created a package with menu items (commands) using the SDK you’ll notice that the default wizard-generated package contains a sample image strip that looks like this:

image

These are the little 16×16 icons that appear on menu items and toolbar buttons. It’s just placeholder artwork for various commands that you might want to implement in your new package. You’re supposed to edit the image to add your own artwork. However, the image is in a strange format: It’s a 32 bits per pixel image with a .BMP extension (the filename is “Images_32bit.bmp”). If you try and edit it in Visual Studio, you’ll find that the built-in image editor doesn’t understand the format. The interesting thing is that this image contains a full 8-bit alpha channel. We’ve come across alpha channels before in the discussion of the Splash Screen and another area where Visual Studio supports full alpha is on menus and toolbars. Unfortunately, the .BMP file specification doesn’t officially support this 32bpp ARGB format and many applications will either refuse to recognize it or will drop the alpha channel on saving.

PNG to the rescue

Since this 32-bit ARGB format is so hard to work with, I suggested to the planning group that we add support for .PNG files to the VSCT compiler (the compiler which reads your package’s command definitions, including these bitmap strips, and produces binary resources). The owner of the VSCT compiler replied and said that there was no need because it already did support .PNG – in fact, it accepts any format that System.Drawing.Image.FromFile supports. Sure enough, after a quick experiment, I confirmed that is true and, indeed, MSDN already has the appropriate note if you know where to look. Somehow, I had assumed that, since the wizard spat out that annoying 32-bit BMP file, that was the only file format supported and, moreover, I don’t think I’ve ever seen anyone use PNG files internally – and I’ve seen a lot of VSCT files in my travails/travels.

Conclusion

So, there you have it. Use .PNG files for your bitmap strips. PNG has, in recent years, become the de-facto standard for images with full-transparency and lossless compression and there are many free image editing applications which support it.

P.S. I wasn’t the first to spot this, and, since I started writing this article and doing a little research, I found a few examples of using .PNG files in VSCT on codeplex. Still I think this little known fact deserves some more visibility. Perhaps in the next version of the SDK we can change the template to emit PNG files by default.

clip_image002

Paul Harrington – Principal Developer, Visual Studio Platform Team. Biography: Paul has worked on every version of Visual Studio .Net to date. Prior to joining the Visual Studio team in 2000, Paul spent six years working on mapping and trip planning software for what is today known as Bing Maps. For Visual Studio 2010, Paul was the architect for the move to WPF. Paul holds a master’s degree from the University of Cambridge, England and lives with his wife and two cats in Seattle, Washington.

Author

Visual Studio has been around since 1997 when it first released many of its programming tools in a bundle. Back then it came in 2 editions - Visual Studio Professional and Visual Studio Enterprise. Since then the family has expanded to include many more products, tools, and services.

0 comments

Discussion are closed.