0
$\begingroup$

In my Linux computer,it can't save Image or Graphics to picture format such as png,jpg,tiff,pdf... but txt is OK

p=Graphics@Circle[];
Export["test.jpg",p];(*always calculating*)

I want to know is there something alternative way to save picture like using JLink?

enter image description here

System

Distributor ID: Ubuntu

Description: Ubuntu 14.04.5 LTS

Release: 14.04

Codename: trusty

I try this code but no image file found.

<< JLink`;
InstallJava[];
outputfile = JavaNew["java.io.File", "test.png"];
img = RandomImage[1, {20, 10}, ColorSpace -> "RGB"];
{h, w} = ImageDimensions[img];
src = JavaNew["java.awt.image.BufferedImage", w, h,BufferedImage`TYPEUINTURGB];
LoadJavaClass["javax.imageio.ImageIO"];
ImageIO@write[src, "PNG", outputfile]

Do I need install some package?

Update:

In my another Linux machine,it raise error.

enter image description here

Using romote kernel from mathematica,it's OK.

enter image description here

Thank you @Szabolcs.

sudo apt-get install xvfb
xvfb-run wolfram

Then it can export Graphics or Image!

$\endgroup$
11
  • 2
    $\begingroup$ This should not really happen. You are saying that Export does not work on Linux? That will be a major bug if this was the case. But what does Directory[] say before you issue the command? $\endgroup$
    – Nasser
    Oct 15, 2017 at 5:44
  • $\begingroup$ It works on my Xubuntu. What specific distro are you using, and what version of Mathematica? $\endgroup$ Oct 15, 2017 at 5:54
  • 1
    $\begingroup$ Why are you using the command line? Is there an X server running? That's required for exporting on Linux. $\endgroup$
    – Szabolcs
    Oct 15, 2017 at 7:38
  • 1
    $\begingroup$ Perhaps you are not aware that an X server is connected. It is not possible to export graphics without one. If you use a remote machine, then you can either forward X using ssh -X / ssh -Y or use Xfvb. $\endgroup$
    – Szabolcs
    Oct 15, 2017 at 8:55
  • 1
    $\begingroup$ @Szabolcs Well done. Thank you! sudo apt-get install xvfb then xvfb-run wolfram,everything is OK!!! $\endgroup$
    – partida
    Oct 16, 2017 at 1:16

0

Browse other questions tagged or ask your own question.