Skip to main content
RSS feed Subscribe to feed

 

Creating Binary Data

This example shows how to create binary data by creating binary images.

The complete code of this example is available in the the Spotfire SDK 2.2:

  • Spotfire SDK\Examples\Extensions\SpotfireDeveloper.ApiExamples\BinaryDataExample.cs
private class MyBinaryDataRowReader : CustomDataRowReader
{
    // ...

    /// <summary>
    /// Setting the cursor values. 
    /// Each row has the row number (starting on 1) in the Number column, 
    /// and the same number as png image in the Binary column.
    /// </summary>
    /// <returns>true for the first 99 rows, false otherwise.</returns>
    protected override bool MoveNextCore()
    {
        // Limit to 99 rows.
        bool result = (++rowCount < 100);

        // Only set values if less than 99 rows.
        if (result)
        {
            // Create a memory stream to use when converting the image to png.
            using (MemoryStream ms = new MemoryStream())
            {
                // Set the integer value
                intCursor.MutableDataValue.Value = rowCount;
                intCursor.MutableDataValue.IsValid = true;

                // Create an image with the rowcount number.
                Image image = new Bitmap(50, 50);
                Graphics graph = Graphics.FromImage(image);
                graph.DrawString(rowCount.ToString(), 
					new Font("Arial", 16), 
					new SolidBrush(Color.Black), 
					new PointF(20.0F, 20.0F));

                // Convert image to png.
                image.Save(ms, ImageFormat.Png);

                // Reset memory stream to get ready to read binary values.
                ms.Position = 0;

                // Create the BinaryLargeObject from the memory stream and set the binary value.
                binaryCursor.MutableDataValue.Value = BinaryLargeObject.Create(ms);
                binaryCursor.MutableDataValue.IsValid = true;
            }
        }

        // Return
        return result;
        
    }
    // ...
}