Windows Phone 8 bitmap transparency

Developer
May 9, 2013 at 9:15 AM
I discovered an issue which has to do with the transparency of a bitmap.
Mapsui uses a SymbolStyle with a Bitmap object, which is in fact a stream:
var symbol = new SymbolStyle { Symbol = new Bitmap { Data = stream} };

In Windows Phone, you must convert a (writeable)bitmap into a stream. This can only be done by saving the bitmap as JPEG. Unfortenately, the transparency information is lost doing so.

When displaying the bitmap as UIElement on the canvas, everything is ok.
@Paul: is there a way around this issue? Any ideas?
Coordinator
May 9, 2013 at 1:12 PM
Take a look at ConverToBitmapStream over here:
https://mapsui.codeplex.com/SourceControl/latest#Mapsui.Rendering.XamlRendering-SL/Utilities.cs
Tell me if it solves your problem.
Developer
May 10, 2013 at 12:09 PM
Sorry, does not work. No transparency.
Coordinator
May 10, 2013 at 2:19 PM
How does your sample behave if you try regular Silverlight?
Developer
May 31, 2013 at 9:17 AM
Solution (thanks Paul):
1) add a PNG file to yout VS project. For example: I added a gps.png file in the /Images folder. The PNG has transparency, of course.
2) Set the property of the PNG to: "Embedded Resource" and "Do not copy".
3) Create a layer (in this example: pointLayer) and use the following code:
pointLayer.Styles.Clear(); //clear default style
var bitmapData = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Mapsui.Samples.WP8.Images.gps1.png");
var symbolStyle = new SymbolStyle { Symbol = new Bitmap { Data = bitmapData } };
pointLayer.Styles.Add(symbolStyle);
4) now the PNG is displayed with transparency!