Store and Retrieve a Bitmap in ECO

This article demonstrates the basics of how to store and retrieve a Bitmap in an ECO variable.

First create an ECO variable in the class you wish to hold the bitmap, for example:

FCanvas: Byte

Note that we really want a byte array, so right click on FCanvas and select "Go to Definition".
You can now change the definition to byte[] as follows:

private byte[] FCanvas

To write the Bitmap to FCanvas use the following:

ImageConverter ic = new ImageConverter();

System.Byte[] ba = (System.Byte[])ic.ConvertTo(bmp,           typeof(System.Byte[]));
    
FCanvas = ba;

To retrieve the bitmap from FCanvas use the following:

System.IO.Stream str = new System.IO.MemoryStream(FCanvas);

Bitmap bmp = new Bitmap(str);

I am sure you will use vastly superior variable names to the mindless concoctions shown, they are not used in shipped code - honest!

 

Share this article!

Follow us!

Find more helpful articles: