tisdag, oktober 23, 2007

 

ReadOnlyDictionary

Since I started using .NET 2.0 I've been wondering why Microsoft didn't provide a ReadOnlyDictionary<k,v> class in the BCL. I just stumbled upon some info where I found this:
internal class ReadOnlyDictionary<K, V> : IDictionary<K,V>, ICollection<KeyValuePair<K, V>>, IEnumerable<KeyValuePair<K, V>>, IDictionary, ICollection, IEnumerable
Name: MS.Internal.Utility.ReadOnlyDictionary
Assembly: WindowsBase, Version=3.0.0.0
This is an internal class in one of the libraries that is shipped with .Net Framework 3.0. But why didn't that class make it into the System.Collections.ObjectModel namespace?
Probably the developers on the team developing the BCL didn't have the time required to push this into the release. However, this suggestion has been on Microsoft Connect for a while.
I wonder if we can expect such a class for the next release...

Etiketter: , ,


lördag, oktober 13, 2007

 

A solution for transparent images on Compact Framework

Recently I worked on the problem of getting full 8-bit image transparency on Windows Forms using the .Net Compact Framework. I have tried to find a nice solution before, but at the time, I didn't find a solution that gave me the results I wanted.
Yesterday I visited the local Microsoft sub-office here in Stockholm to attend to a Mobility Day event. After the event I sent an e-mail to David Goon (ADC at Microsoft Ltd., UK), the guy who held the talk during the second part of the day. He showed the audience a numerous of cool new things that you can do with the Microsoft Mobile Sample wrapper APIs for GPS integration, message interception using the Messaging API, and a few cool things with the Camera API (but that's another blog entry :)).
I asked him if he was aware of a solution to my transparency problem what regards Windows Mobile 5+6, and he led me to my previous stop in an attempt to achieve this effect:
"With regards to alpha blending, the following blog might give you some clues: http://blogs.msdn.com/chrislorton/archive/2006/04/07/570649.aspx."

After re-reading Chris' sample code, I modified it a bit to suite my needs. My example code can be downloaded here.

I created two new classes that uses the imaging features that Chris uses:
AlphaImage - A wrapper class for the IImage interface that can be used like the System.Drawing.Image class (but with alpha support of course).
AlphaImageControl - A form widget that works like the PictureBox that uses an AlphaImage instance. This widget can of course easily be accessed from the toolbox in the IDE.

The image I have used in my example is a 24-bit PNG with white text surrounded by a lot of transparent pixels. The form that the image control is placed on has a solid background color (SystemColors.Control).

Here is a capture from the emulator of the result:And what you will see in the IDE designer is:

Thanks Chris for an excellent piece of code (this is your code, I just wrapped it all together).
Thanks David for pointing me back in the right direction!

According to my tests, this works just fine in the PocketPC emulator (see attached image) using Windows Mobile 5 as well as on a HTC TyTn II device, which operates on Windows Mobile 6 Professional Edition. However, I can not guarantee that this will work as expected on any Windows Mobile device.
This posting is provided "AS IS" with no warranties.

AlphaImageExample.zip

Etiketter: , , ,


Prenumerera på Inlägg [Atom]