As you migrate your business solution application from previous .NET Winform/ASP.NET to microsoft WPF/Silverlight and you wish to reused the existing satellite resource dll which you have created in the pass.
Due to the image object is different between the .NET WinForm/ASP.NET (
Bitmap) and WPF/Silverlight (
BitmapImage). Which mean, we are not able to call
GetObject() in ResourceManager and assign the image into the
BitmapImage object in WPF/Silverlight.
1: BitmapImage bmpRaw = (BitmapImage)ResourceManager.GetObject("MyImage"); Instead, we have to load the return Bitmap object into
MemoryStream before further assign to the
BitmapImage object via the
BitmapImage.StreamSource property.
1: System.IO.MemoryStream stream = new System.IO.MemoryStream();
2: bmpRaw.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
3: bmp.StreamSource = stream;
Again, here we have another hidden trap in the
MemoryStream object! That is the
MemoryStream data position (data address pointer) is set as end of data position after the
Bitmap.Save()
Therefore, we must move the data position back to the begin position before we further use it in
BitmapImage.StreamSource()
1: stream.Seek(0, System.IO.SeekOrigin.Begin);
[More]