matlab - 显示新图像时如何使 Matlab 图形窗口最大化?

标签 matlab user-interface figure

我正在 Matlab 中编写一个 GUI 用于实验,测试参与者将查看一系列图像,并在每张图像后回复对该图像的评分。

我想一直保持窗口最大化。图像将显示几秒钟,然后移除,一些 slider 将出现用于评级。接下来, slider 将被隐藏,并出现一个新图像,等等......

到目前为止,我从最大化图形窗口开始就很好,直到我使用 imshow 或图像命令加载图像并显示它,这会导致图形窗口调整大小并适合图像,而不是保持最大化。如果我然后再次最大化图形窗口,它会导致窗口框架明显闪烁,首先最大化,然后调整大小,然后再次最大化 - 我想避免的闪烁。

如何保持窗口最大化,并以 1:1 的比例显示图像(不缩放或调整大小以适应最大化的窗口)?

我知道 PsychToolbox,但它似乎没有创建 slider 的命令(我会用它来进行评级),我不想从头开始做这些。 我还研究了来自 Matlab File Exchange 的 windowAPI,但仍未找到解决方案。

下面是我现在拥有的示例(在 Windows 7 64 位上使用 Matlab R2013a):

screenSize = get(0,'screensize');
screenWidth = screenSize(3);
screenHeight = screenSize(4);

% Create figure window, keeping it invisible while adding UI controls, etc.
hFig = figure('Name','APP',...
    'Numbertitle','off',...
    'Position', [0 0 screenWidth screenHeight],...
    'WindowStyle','modal',...
    'Color',[0.5 0.5 0.5],...
    'Toolbar','none',...
    'Visible','off');

% Make the figure window visible
set(hFig,'Visible','on');

% Maximize the figure window, using WindowAPI
WindowAPI(hFig, 'Position', 'work');

% Pause (in the full version of this script, this would instead be
% a part where some UI elements are shown and later hidden...
pause(1.0);

% Read image file
img = imread('someImage.png');

% Create handle for imshow, and hiding the image for now.
% This is where Matlab decides to modify the figure window,
% so it fits the image rather than staying maximized.
hImshow = imshow(img);
set(hImshow,'Visible','off');

% Show the image
set(hImshow,'Visible','on');

谢谢, 基督徒

最佳答案

尝试将 'InitialMagnification' 参数与 'fit' 选项值一起用于 imshow:

hImshow = imshow(img,'InitialMagnification','fit')

来自 this MathWorks tutorial :

You can also specify the text string 'fit' as the initial magnification value. In this case, imshow scales the image to fit the current size of the figure window

另见 this section of the imshow docs关于 'InitialMagnification'。因此,这应该使您的图形窗口保持相同大小。

这将解决丢失窗口最大化的问题。


要在屏幕上以 1 像素到 1 点的比例显示图像,您可以为图像创建一个正确大小的轴,并显示到其中:

fpos = get(hFig,'Position')
axOffset = (fpos(3:4)-[size(img,2) size(img,1)])/2;
ha = axes('Parent',hFig,'Units','pixels',...
          'Position',[axOffset size(img,2) size(img,1)]);
hImshow = imshow(img,'Parent',ha);

请注意,没有必要指定放大倍率,因为“如果您指定轴位置(使用子图或轴),imshow 会忽略您可能已指定的任何初始放大倍率并默认为 ” fit' behavior”,从而适合由 'Parent' 指定的轴。

关于matlab - 显示新图像时如何使 Matlab 图形窗口最大化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19989565/

相关文章:

matlab - 如何以编程方式在方法的开头放置断点?

Android AsyncTask 卡住 UI

Android Espresso : cannot resolve symbol AndroidJUnit4. 类

python - Matplotlib 弃用 在 plt.show() 中设置值时发出警告。关键词是什么?

python - Matplotlib 窗口大小、标题等

matlab - 获取麦克风的频率响应

matlab - 如何在 MATLAB 中并行化输入和显示?

matlab - 我怎样才能无限期地循环,但在某些情况下停止?

powershell - PowerShell 中是否有用于交互式提示的模块或类似的东西?

algorithm - 对矢量场进行颜色编码