我正在尝试使用 Matlab 保存图像print
功能:
myImage = magic(500);
myFigure = figure('visible','off');
r = 1;
set(myFigure, 'PaperUnits', 'inches', 'PaperPosition', [0 0 1920 1080]/r);
% the program works fine on both computers without the line above
% however, the program runs fine on one computer only with this line
imagesc(myImage); axis image;
print(myFigure, '-dpng', sprintf('-r%d',r), 'myOutput.png');
当我使用 Matlab R2012b 在本地运行该程序时,它按预期工作。但是,如果我尝试使用 Matlab R2011b 在远程计算机上运行它,则会收到以下错误消息:
Error using ghostscript (line 188)
Problem converting PostScript. System returned error: -1.Failed to convert to
output format; Ghostscript status: -100.**** Unable to open the initial device,
quitting.
以及由调用的行触发的以下错误print()
:
Error in print>LocalPrint (line 311)
pj = ghostscript( pj );
Error in print (line 237)
LocalPrint(pj);
代码更具体:
if pj.GhostDriver
pj = ghostscript( pj );
elseif strcmp( pj.Driver, 'hpgl' )
hpgl( pj );
end
在我的笔记本电脑上,pj.GhostDriver
is ''
and pj.Driver
is png
.
一种可能的解释是我可以从终端本地启动 Ghostscript:
$ ghostscript
GPL Ghostscript 9.10 (2013-08-30)
Copyright (C) 2013 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
GS>
但不是从终端远程(因为我在远程计算机上没有任何图形界面):
$ ghostscript
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
GPL Ghostscript 9.05: Cannot open X display `(null)'.
**** Unable to open the initial device, quitting.
我本以为 Matlab 已经知道了,因为我在both计算机使用:
matlab -nosplash -nodesktop -singleCompThread
此外,就终端而言,通过添加以下行可以轻松解决此问题~/.bashrc
:
export GS_DEVICE=display
有解决方案的提示吗?