Can I get the exact reason why the function Image doesn't yield a proper output in the below?

Image[TreeForm@{1, 2, 3}]

It shows an error message as below.

Image::imgarray: The specified argument  should be an array of rank 2 or 3 with machine-sized numbers. >>

Is there anyway not to use the function Rasterize for get an image for the TreeForm expression?


closed as off-topic by Oleksandr R., RunnyKine, user9660, MarcoB, WReach Apr 11 '16 at 14:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Oleksandr R., RunnyKine, Community, MarcoB, WReach
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ You don't need Image just use TreeForm@{1,2,3} $\endgroup$ – e.doroskevic Jan 11 '16 at 20:18
  • 2
    $\begingroup$ Rasterize works, assuming you want a raster whats wrong with that? $\endgroup$ – george2079 Jan 11 '16 at 20:36
  • 1
    $\begingroup$ Graphics[Inset[TreeForm@{1, 2, 3}]] gets you a graphic object.. (trying to guess what you want.. ) $\endgroup$ – george2079 Jan 11 '16 at 20:38
  • 1
    $\begingroup$ @george2079, or ToExpression@ToBoxes@TreeForm@{1, 2, 3} $\endgroup$ – Simon Woods Jan 11 '16 at 20:40
  • $\begingroup$ @george2079 Thanks a lot. That is what I wanted! $\endgroup$ – Smart Humanism Jan 12 '16 at 4:25

If you want to get the Graphics representation of TreeForm, you'll need to convert it to boxes first, and then convert these boxes into a Graphics expression. The reason is that TreeForm is a special display form, and is converted directly into boxes for display without actually being evaluated into Graphics by the kernel.

g = TreeForm[{1, 2, 3}] // MakeBoxes // ToExpression;
Head[g] (* -> Graphics *)

You don't mention in the question what you want to do with this output, but if you use Image on this Graphics, you will indeed get a raster image. (Personally, I think this application of Image is misguided. Image is nominally supposed to represent a raster image based on given pixel values, not create one from other objects, which is the job of Raster...)

I will note that the result of Image[g] is identical to that of Rasterize[TreeForm[{1, 2, 3}], "Image"], so it's not clear to me what you hoped to avoid by refusing to use Rasterize here.



{1, 2, 3} // TreeForm






Not the answer you're looking for? Browse other questions tagged or ask your own question.