0

Let say I have application menus in a database with their icon images (binary data). I extract those menus with the icons being byte[] type. However if there's no icon set, then I would like to use default icon which comes not from database, but from xap (inside Resources folder). To display icons coming from database I use IConverter (byte[] to image), which is based on the code of the following question:

Silverlight 4.0: How to convert byte[] to image?

To be able to use my byte[]-to-image IConverter, I would also like to convert my default icon to byte[], which comes from xap. How I can do that? The following question suggested to use WriteableBitmap class, but I don't know how to create WriteableBitMap from the xap source:

Silverlight: image to byte[]

Community
  • 1
  • 1
synergetic
  • 7,756
  • 8
  • 65
  • 106

2 Answers2

1

I may be miss understanding the question here (perhaps more details about your converter are required here), but if you converter class just returns an image based on its bytes, cant you just test for null bytes from the DB, then return your default image?

public class MyConveter : IConverter {
    public Image ConvertImage(byte[] bytes) {
        if (bytes == null) return GetDefaultImage();
        else return ConverterBytesToImage(bytes);
    }
}

this way you simply return an image as the method declaration, and the implementation handles the null bytes case.

Is this on the right track?

Mark
  • 14,820
  • 17
  • 99
  • 159
0

As your default icon is a resource, you can open it as a ResourceStream and just read it in as bytes.

Would that meet your requirements?

iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202