IKernelLinkEvaluateToImageBytes Method

Sends graphics or plotting code for evaluation and returns the result as an array of bytes in the specified bitmap format.

Remarks

This method sends the evaluation and waits for the result to come back as an array of image bytes. It discards any packets other than the result (for example, Wolfram Language messages or Print output).

It does not throw a MathLinkException. Instead it returns null if there was an error. You can use the LastError property to see the MathLinkException that was generated.

For programs running on Microsoft Windows, or on Linux when using Mono, you might find it more useful to use the EvaluateToImage(String, Int32, Int32) method, which returns the set of graphics as an array of Image objects. The EvaluateToImage(String, Int32, Int32) method is intended primarily for programs that run in an environment where the Image class is not available (i.e., Mac, and Linux when using dotnet).

The image will be sized to just fit within a box of width x height, without changing its aspect ratio. This means that the image might not have exactly these dimensions, but it will never be larger.

You can use the GraphicsFormat property to control the format in which the image is returned.

If the input does not evaluate to a graphics expression, null is returned. It is not enough that the computation causes a plot to be generated--the return value of the computation must be a Wolfram Language Graphics (or Graphics3D, SurfaceGraphics, etc.) expression. For example:
C#
BAD:  ml.EvaluateToImageBytes("Plot[x,{x,0,1}];", 400, 400);
GOOD: ml.EvaluateToImageBytes("Plot[x,{x,0,1}]", 400, 400);

Overload List

EvaluateToImageBytes(Expr, Int32, Int32) Sends the code to evaluate as an Expr.
EvaluateToImageBytes(String, Int32, Int32) Sends the code to evaluate as a string.

See Also