Recently I have some requirement to extract Navision item picture to web front application and with Navision 2009 I could store not only BMP format but many other format namely, JPEG, TIFF, PNG and etcetera.  This is indeed is great improvement in Navision 2009, since BMP format is not the best format due the size of the space. Now, I have a little problem with the format diversity on how to recall the image format type. I need find out the format type because the web pages require the right content type before it can display correctly.

After some study and research, finally I can make a simple function in Navision C/AL to detect the image format type directly from the blob image field. Basically some bytes at the beginning of the image store the image format information. So, I need the first 4 characters from the BLOB image and do checking with it.  The function below detects some major image format and could be extended to detect others whenever it is necessary.

Content Type Function Detector

Below C/AL code  is using detector function for displaying the content type format of item picture:

                            

l_recItem.CALCFIELDS(Picture);
IF l_recItem.Picture.HASVALUE THEN BEGIN
   l_recItem.Picture.CREATEINSTREAM(l_instreamBigData);
   l_instreamBigData.READTEXT(l_textLen4);
   l_textContentType := l_cduGenFunction.GetImageContentType(l_textLen4);
   Message(’Image Format is : ‘ + l_textContentType);
END;