c# - Creating BitmapImage from a byte array -
i trying create bitmapimage
byte array returned service.
my code is:
using (sc = new serviceclient()) { using (memorystream ms = new memorystream(sc.getimage())) { display = new bitmapimage(); display.begininit(); display.streamsource = ms; display.endinit(); } }
however, exception thrown @ endinit
method. says object reference not set instance of object.
.
it seems, uri null , causes problem. unfortunately, cannot find solution myself.
well, turned out, wpf binding causing error.
private bitmapimage _display; public bitmapimage display { { return _display; } set { _display = value; raisepropertychanged("display"); } }
i resolved issue getting image not in property display itself, rather in filed _display. so, following working fine.
using (sc = new serviceclient()) { using (memorystream ms = new memorystream(sc.getimage())) { _display = new bitmapimage(); _display.begininit(); _display.cacheoption = bitmapcacheoption.onload; _display.streamsource = ms; _display.endinit(); } } display = _display;
Comments
Post a Comment