在Matlab中为图形设置dpi

问题描述

我在数字dpi方面遇到了一个小问题,或者Windows只是在拖曳我。 我使用以下行打印图像

fig =gcf;
fig.PaperPositionMode = 'auto';
print('ScreenSizefigure',-djpeg,'-r600');

这是根据窗口得出的图像统计信息:

  • 尺寸:11900x6169
  • 宽度11900
  • 像素高度6169像素
  • 水平分辨率96 dpi
  • 垂直分辨率96 dpi

Matlab(我正在使用Matlab R2019b Update 6),我的代码有问题吗?还是Windows只是给我错误的信息? 我感谢所有帮助。

解决方法

在某种程度上这是一个已知问题。您可能想尝试另一个Matlab函数。 export_fig.m exports figures nicely to a number of vector & bitmap formats

以下是一些演示: https://github.com/altmany/export_fig/blob/master/README.md

,

如果只是一个图形,请使用导出设置的GUI。

MATLAB's export setup

文件>导出设置...>渲染>分辨率(dpi) +不要忘记单击应用于图形

如果您需要导出具有相同大小/字体/渲染效果的多个图形,定义一个导出样式会很方便。定义好后,您可以使用以下简单功能将其自动加载并应用到图形中:

function FigExport(fh,FileName,ExpStyl)
%%
ax = get(fh,'children');
lg = arrayfun(@(x)isa(x,'matlab.graphics.axis.Axes'),ax);
if ~all(cellfun(@(x)strcmp(x,'on'),{ax(lg).Box}))
    box(ax(lg),'on')
end

% get style sheet info
if nargin < 3 || isempty(ExpStyl)
    ExpStyl = 'PPT'; % The name of your style file (NO extension)
end
s = hgexport('readstyle',ExpStyl);

%% apply style sheet info & export file
if isempty(FileName)
    FileName = 'tmpFigExprt';
end

s.Format = 'jpeg'; %I needed this to make it work but maybe you wont.
hgexport(fh,s);
end