Share via


Decoding image blobs obtained from OData query services

This post on the OData Query Service is by Principal Software Architect Arthur Greef.

Images retrieved using OData query services are returned as base 64 encoded containers. The following code will decode the image container into a byte array that contains just the image.

string base64EncodedString = "<place your base64 encoded blob here>";

byte[] serializedContainer = Convert.FromBase64String(base64EncodedString);

byte[] modifiedSerializedContainer = null;

 if (serializedContainer.Length >= 7 &&

        serializedContainer.Take(3).SequenceEqual(new byte[] { 0x07, 0xFD, 0x30 }))

{

    modifiedSerializedContainer = serializedContainer.Skip(7).ToArray();

}

File.WriteAllBytes("<image file name here>", modifiedSerializedContainer);

 

This posting is provided "AS IS" with no warranties, and confers no rights.