0

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!

partida
  • 6,816
  • 22
  • 48
  • 2
    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? – Nasser Oct 15 '17 at 05:44
  • It works on my Xubuntu. What specific distro are you using, and what version of Mathematica? – J. M.'s missing motivation Oct 15 '17 at 05:54
  • @J.M. 11.1.1 version – partida Oct 15 '17 at 06:08
  • Thanks for the video. It fails because you are using TimeConstrained

    This is expected. If operation do not complete in the time gives, it will abort.

    So what you have to do, is remove the TimeConstrained It looks like it needs more than one second to do the export. Any reason why you are using TimeConstrained by the way? Here is an example TimeConstrained[NextPrime[1000], 0.0001] which gives $Aborted

    – Nasser Oct 15 '17 at 06:23
  • @Nasser Using TimeConstrained just explained this problem, so I used that function.Even for ten minutes, it could not export it.I can't record gif for long time, so I used one second. – partida 32 mins ago – partida Oct 15 '17 at 07:03
  • 1
    Why are you using the command line? Is there an X server running? That's required for exporting on Linux. – Szabolcs Oct 15 '17 at 07:38
  • @Szabolcs But in Raspberry pi,it can export even no X server running – partida Oct 15 '17 at 08:50
  • 1
    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. – Szabolcs Oct 15 '17 at 08:55
  • But Export does not use the graphical interface, why the server be open? In python,Export is directly feasible – partida Oct 15 '17 at 10:55
  • Graphics are rendered by the front end, not the kernel. The Linux version of the front end cannot run without an X server. Common solutions are X forwarding, Xvfb or Xvnc. You may be having the last one of these already running on your Raspberry Pi. – Szabolcs Oct 15 '17 at 12:42
  • 1
    @Szabolcs Well done. Thank you! sudo apt-get install xvfb then xvfb-run wolfram,everything is OK!!! – partida Oct 16 '17 at 01:16

0 Answers0