我错过了自动最大化图像的步骤。
有什么建议吗? 到目前为止,我只发现了这个:
http://answers.yahoo.com/question/index?qid=20071127135551AAR5JYh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/238699
但是没有一个解决我的问题。
http://answers.yahoo.com/question/index?qid=20071127135551AAR5JYh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/238699
但是没有一个解决我的问题。
figure('units','normalized','outerposition',[0 0 1 1])
或者对于当前图形:
set(gcf,'units','normalized','outerposition',[0 0 1 1])
我还使用了在FileExchange上使用Java编写的MAXIMIZE函数。这是真正的最大化。
想要实现最大化窗口(就像在OS X和Windows的用户界面中点击最大化按钮一样),您可以尝试以下方法,调用一个隐藏的Java句柄:
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
pause(n)
是必要的,因为上述代码跳出了 Matlab 的范畴,并运行在一个独立的 Java 线程上。将 n
设置为任意值并检查结果。计算机执行速度越快,n
可以设置得越小。
这里可找到完整的“文档”.
警告:JavaFrame图形属性将在未来版本中被删除。有关更多信息,请参见mathworks.com上的Java和ActiveX用户建议。
Matlab R2019b @ Win10 64位 - winkmal从R2018a开始, figure
和 uifigure
对象都包含一个叫做 WindowState
的属性。默认情况下,它被设置为 'normal'
,但将其设置为 'maximized'
可以得到期望的结果。
总之:
hFig.WindowState = 'maximized'; % Requires R2018a
Making figures maximized by default is possible using:
set(groot, 'defaultFigureWindowState', 'maximized');
Maximizing all open figures is possible using:
set(get(groot, 'Children'), 'WindowState', 'maximized');
More information about 'WindowState'
as well as other properties controlling figure appearance can be found in this documentation page.
export_fig
工具。set(groot,'defaultFigureWindowState','maximized');
- Unknown123Figure Properties
文档 https://www.mathworks.com/help/matlab/ref/matlab.ui.figure-properties.html 中的 Window Appearance
部分,了解有关 WindowState
的更多信息。 - Unknown123h = figure; %// create figure and get handle
plot(1:10); %// do stuff with your figure
figure(h) %// make it the current figure
robot = java.awt.Robot;
robot.keyPress(java.awt.event.KeyEvent.VK_ALT); %// send ALT
robot.keyPress(java.awt.event.KeyEvent.VK_SPACE); %// send SPACE
robot.keyRelease(java.awt.event.KeyEvent.VK_SPACE); %// release SPACE
robot.keyRelease(java.awt.event.KeyEvent.VK_ALT); %// release ALT
robot.keyPress(java.awt.event.KeyEvent.VK_X); %// send X
robot.keyRelease(java.awt.event.KeyEvent.VK_X); %// release X
完成!窗口已最大化!
正如上面的作者所提出的那样, 如果你想模拟点击“最大化”窗口按钮,你可以使用下面的代码。与提到的答案不同的是,使用“drawnow”而不是“pause”似乎更正确。
figure;
% do your job here
drawnow;
set(get(handle(gcf),'JavaFrame'),'Maximized',1);
在我看来,将图形窗口最大化并不是以更高分辨率保存图像的最佳方式。
有关于打印和保存的图形属性。使用这些属性,您可以按照任何您想要的分辨率保存文件。为了保存文件,您必须使用print函数,因为您可以设置一个dpi
值。所以,首先设置以下图形属性:
set(FigureHandle, ...
'PaperPositionMode', 'manual', ...
'PaperUnits', 'inches', ...
'PaperPosition', [0 0 Width Height])
其次,将文件保存为png格式,并设置分辨率为100dpi(例如使用'-r100'
参数)。
print(FigureHandle, Filename, '-dpng', '-r100');
2048x1536px
的文件,请将 Width = 2048/100
和 Height 1536/100
,因为您使用的是 100dpi 进行保存所以要除以 /100
。如果您更改 dpi 值,您也必须将除数更改为相同的值。screen_size = get(0, 'ScreenSize');
f1 = figure(1);
set(f1, 'Position', [0 0 screen_size(3) screen_size(4) ] );
%% maximizeFigure
%
% Maximizes the current figure or creates a new figure. maximizeFigure() simply maximizes the
% current or a specific figure
% |h = maximizeFigure();| can be directly used instead of |h = figure();|
%
% *Examples*
%
% * |maximizeFigure(); % maximizes the current figure or creates a new figure|
% * |maximizeFigure('all'); % maximizes all opened figures|
% * |maximizeFigure(hf); % maximizes the figure with the handle hf|
% * |maximizeFigure('new', 'Name', 'My newly created figure', 'Color', [.3 .3 .3]);|
% * |hf = maximizeFigure(...); % returns the (i.e. new) figure handle as an output|
%
% *Acknowledgements*
%
% * Big thanks goes out to Yair Altman from http://www.undocumentedmatlab.com/
%
% *See Also*
%
% * |figure()|
% * |gcf()|
%
% *Authors*
%
% * Daniel Kellner, medPhoton GmbH, Salzburg, Austria, 2015-2017
%%
function varargout = maximizeFigure(varargin)
warning('off', 'MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame')
% Check input variables
if isempty(varargin)
hf = gcf; % use current figure
elseif strcmp(varargin{1}, 'new')
hf = figure(varargin{2:end});
elseif strcmp(varargin{1}, 'all')
hf = findobj('Type', 'figure');
elseif ~isa(varargin{1}, 'char') && ishandle(varargin{1}) &&...
strcmp(get(varargin{1}, 'Type'), 'figure')
hf = varargin{1};
else
error('maximizeFigure:InvalidHandle', 'Failed to find a valid figure handle!')
end
for cHandle = 1:length(hf)
% Skip invalid handles and plotbrowser handles
if ~ishandle(cHandle) || strcmp(get(hf, 'WindowStyle'), 'docked')
continue
end
% Carry the current resize property and set (temporarily) to 'on'
oldResizeStatus = get(hf(cHandle), 'Resize');
set(hf(cHandle), 'Resize', 'on');
% Usage of the undocumented 'JavaFrame' property as described at:
% http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/
jFrame = get(handle(hf(cHandle)), 'JavaFrame');
% Due to an Event Dispatch thread, the pause is neccessary as described at:
% http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/
pause(0.05)
% Don't maximize if the window is docked (e.g. for plottools)
if strcmp(get(cHandle, 'WindowStyle'), 'docked')
continue
end
% Don't maximize if the figure is already maximized
if jFrame.isMaximized
continue
end
% Unfortunately, if it is invisible, it can't be maximized with the java framework, because a
% null pointer exception is raised (java.lang.NullPointerException). Instead, we maximize it the
% straight way so that we do not end up in small sized plot exports.
if strcmp(get(hf, 'Visible'), 'off')
set(hf, 'Units', 'normalized', 'OuterPosition', [0 0 1 1])
continue
end
jFrame.setMaximized(true);
% If 'Resize' will be reactivated, MATLAB moves the figure slightly over the screen borders.
if strcmp(oldResizeStatus, 'off')
pause(0.05)
set(hf, 'Resize', oldResizeStatus)
end
end
if nargout
varargout{1} = hf;
end
这是最短的形式
figure('Position',get(0,'ScreenSize'))
set
命令来更改图形的 MenuBar
和 Toolbar
属性。由于它适用于更旧和更新版本的 Matlab,所以 set
命令更加灵活多用。fig = figure(1);
set(fig, 'MenuBar', 'none');
set(fig, 'ToolBar', 'none');
set
将您的图形设置为全屏。set(fig, 'Position', get(0,'Screensize'));