How to draw inside a blob field with NAV 2013

With .NET interoperability it is possible to draw inside a NAV 2013 BLOB field. Consider the following snippet of code. “Picture Blob” is a BLOB field. We create a OutStream so we can write information into the blob. We must calc a BLOB field, even if its empty before getting the OutStream.

GenerateBitmap is a function that does the following:

  1. Creates a Bitmap instance (Size 50×50)
  2. Creates a Graphics instance on the bitmap
  3. Creates a SolidBrush in a specific color, in this case from a HTML color code.
  4. Draws an filled ellipse on the graphics in 0,0 -> 49,49 (bitmaps are 0-indexed)
  5. Saves the bitmap on the OutStream from our BLOB field.

All variables can be found in the System.Drawing Assembly.

This could be extended so we can draw on a existing BLOB field. So instead of creating a new Bitmap instance, we load the bitmap from an InStream.

And still saves to the OutStream. So you just have to create both the InStream and the OutStream from a BLOB.

[follow_me]