I'm using MMA 8.0 to provide backend on a .NET application I'm writing. I am trying to use the high-level Wolfram.NETLink.MathKernel interface to export an image created with GraphPlot[].
Although the Result comes back as '-Graphics-', I find that Graphics[] is empty. Changing the Compute() to another graphic generating command returns an image in the Graphic[] as expected.
Here's my example code:
Wolfram.NETLink.IKernelLink _iKernelLink;
string cmdLine = "-linkmode launch -linkname \"C:/Program Files/Wolfram Research/Mathematica/8.0/MathKernel.exe\"";
_iKernelLink = Wolfram.NETLink.MathLinkFactory.CreateKernelLink(cmdLine);
_iKernelLink.WaitAndDiscardAnswer();
var k = new Wolfram.NETLink.MathKernel(_iKernelLink); // new MathKernel
k.AutoCloseLink = true; // close link when object is disposed
k.CaptureGraphics = true; // capture graphics output
k.CapturePrint = true; // capture print output
k.CaptureMessages = true; // capture messages
k.HandleEvents = true; // lets Compute thread handle application events
k.UseFrontEnd = false; // don't use Mathematica Notebook front-end
// this produces empty Graphic[] result
string command = @"GraphPlot[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4}]";
// this command produces the expected Graphic[] result
//string command = @"BarChart@Range[5]";
k.Compute(command);
if (k.Graphics.Length > 0) // <-- should be an image for both commands
return k.Graphics[0];
else
return null;