Image from Mathematica to Java

I am trying to get an image from Mathematica. I am trying to evaluate some Mathematica Code that uses methods in packages to generate graphics. If I paste the code into Mathematica notebook, the graphic file is generated correctly.

So my question is:

How to get this graphics in Java ???

Here is my sample code:

ml = MathLinkFactory.createKernelLink("-linkmode launch -linkname 'F:\\APPS\\Wolfram
Research\\Mathematica\\7.0\\mathkernel.exe'");

ml.addPacketListener(new MyPacketListener());
ml.discardAnswer();
PacketListener stdoutPrinter = new PacketPrinter(System.out);
ml.addPacketListener(stdoutPrinter);
// In stringList there is all the INPUT for Mathematica
for (int i = 0; stringList.size() > i; i++) 
{
  System.out.println("Input" + "[" + i + "]" + stringList.get(i));
  ml.evaluate(stringList.get(i));
  ml.discardAnswer();   
 }
ml.close();



class MyPacketListener implements PacketListener {
public boolean packetArrived(PacketArrivedEvent evt)
        throws MathLinkException {
    if (evt.getPktType() == MathLink.TEXTPKT) {
        KernelLink ml = (KernelLink) evt.getSource();
        System.out.println(ml.getString());
    }
    return true;
 }

Output:

<<CIP`ExperimentalData`
<<CIP`MLR`
dataSet = CIP`ExperimentalData`GetQSPRDataSet02[];
CIP`Graphics`ShowDataSetInfo[{"IoPairs", "InputComponents", "OutputComponents"},  
    dataSet];
Number of IO pairs = 2169


Number of input components = 130

Number of output components = 1

mlrInfo = CIP`MLR`FitMlr[dataSet];
mlrInfoInInputForm = InputForm[mlrInfo];
pointSize = 0.025;
CIP`MLR`ShowMlrSingleRegression[{"ModelVsDataPlot", "CorrelationCoefficient"}, 
  dataSet, mlrInfo, GraphicsOptionPointSize -> pointSize];

(*-Graphics-*)
(*
Out 1 : Correlation coefficient = 0.999373
*)
pointSize = 0.01;
CIP`MLR`ShowMlrSingleRegression[{"AbsoluteSortedResidualsPlot", 
   "AbsoluteResidualsStatistics", "RMSE"}, 
   dataSet, mlrInfo, GraphicsOptionPointSize -> pointSize];

(*-Graphics-

Definition of 'Residual (absolute)': Data - Model

                                                                        -1
Out 1 : Residual (absolute): Mean/Median/Maximum Value = 1.4 / 9.84 × 10   / 

             1
>   1.79 × 10

Root mean squared error (RMSE) = 2.063

*)

How to get these -Graphics-?

Thanks for the help!

+3
source share
4 answers

The J / Link user guide has some good code examples for sending graphics from Mathematica to Java: http://reference.wolfram.com/mathematica/JLink/tutorial/CallingJavaFromMathematica.html#29556

+4
source

Export , Java? :

Export["filename.gif",yourPicture]

.gif (.png, jpg,.eps,.tif).

Edit

Java, , , , , , , . Mathematica, ? . , stringList Java, Java.

stringList Export , Java.


, , ShowMlrSingleRegression, , , , Print Do. , . Export . , JavaLink.

+2

Mathematica, . Java File.createTempFile(...).

+1

, java - mathematica, , , .

Perhaps you could check out this library ...

Regards, Stéphane

0
source

All Articles