The official source of product insight from the Visual Studio Engineering Team
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.
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:
These are the little 16x16 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.
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.
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.
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.
So is there any chance this wizard is going to be updated so it actually generates code that's worth using as a starting point?
Of course, that's a dangerous slippery slope. There's *a lot* of wizards in Visual Studio that could do with a similar update. But still, we can hope, right? ;)
What about images for tool windows? When I reconsider correctly VS only allows 24 bit BMP files without transparency there.
I make no promises, but it's likely that we can get the template updated for the next release of the Visual Studio SDK. We may also be able to put something up on the Visual Studio Gallery. I'll see what I can make happen.
Yes, Immo, you can also use PNG files for tool window icons but only if you are targeting Visual Studio 2010 and only if you are writing a managed package (VB or C#).
Hi Paul! That makes sense. Thank you very much for the quick response! :-)
There to be a bug in how the GDI handles EMF files.
-Large EMFs causes memory related exceptions (some time hard crashes).
-EMFs that are loaded using Image.FromFile or Image.FromMemoryStream, then Saved as a PNG using Bitmap.Save() sometimes show text and lines as much thicker and bolder than the original. Even if you play back an EMF before saving as PNG the problem persist.
-You can see this by creating an excel chart, inserting into word as a Metafile, then using simply extracting and opening that EMF in something like Windows Image Viewer.
VS 2010 apparently lacks the ability to edit images in the .png format, regardless whether it supports them. Would like to see that capability added (or better documentation that explains how, since I've yet to find it).