IKernelLinkEvaluateToImage Method

Sends graphics or plotting code for evaluation and returns the result as an Image object.

Remarks

This method sends the evaluation and waits for the result to come back as an Image. 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.

This method relies on the System.Drawing.Image class, which is only available to programs running on Microsoft Windows, or running on Linux when using Mono. On other platforms you can instead use the EvaluateToImageBytes(String, Int32, Int32) property to get the graphics as an array of bytes.

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.EvaluateToImage("Plot[x,{x,0,1}];", 400, 400);
GOOD: ml.EvaluateToImage("Plot[x,{x,0,1}]", 400, 400);

Overload List

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

See Also