I have the following code in Java, where I am trying to use the WolframAlpha command and get the result as a list of images (byte arrays)
String expr = "WolframAlpha[\"solve x^2+2x+1=0\", \"PodImages\", IncludePods->\"Result\", PodStates->\"Step-by-step solution\"]"
mathLink.evaluate(expr)
Evaluating the expression in a terminal gives me something like this. Using the Export function, I've seen the 2 images and they look right.
In[6]:= WolframAlpha["solve x^2+2x+1=0","PodImages", IncludePods->"Result", PodStates->"Step-by-step solution"]
Out[6]= {-Image-, -Image-}
I've tried to get the result as a byte[][] (mathLink.getByteArray2()
), but I get the MLGet out of sequence
exception, so I assumed the result I got wasn't an array of byte arrays.
I also tried getting the result as an Object, but I got the error that Expression on link is not a valid Java object reference
Doing mathLink.getType()
told me that the result that I'm getting is a MTFUNCTION
, so I tried reading the result as a function. Investigating further, I found out that the function type was List
with 2 arguments. I'm assuming that those 2 arguments are the 2 images I want to get.
So my question is: How can I extract the images from the result as an array or list in Java?
Sorry if this is a silly question - I'm new to using JLink and the Wolfram Language
EDIT
In case this helps anyone, I tried logging the output from mathLink.getExpr().toString()
and got:
{
Image[
NumericArray[
{{
{255, 255, 255}, {255, 255, 255}, ...more of these
}},
"UnsignedInteger8"
],
"Byte",
Rule[ColorSpace, "RGB"],
Rule[ImageSize, Automatic],
Rule[Interleaving, True],
Rule[Magnification, 1]
],
Image[
...more of the same as above
]
ImageData
(and in case of list of images —Map
over it), something like: $\endgroup$