How can I keep figure window maximized when showing an image?
古いコメントを表示
I am building a programmatic GUI for an experiment where a test participant will view a series of images, and after each image, respond with a rating for the image.
I want to keep the window maximized, so desktop clutter etc. will not disturb the visual impression. An image will be displayed for a few seconds, then removed, and some sliders will appear for the rating. Next, the sliders will be hidden, and a new image will appear, etc.
What happens is, it starts out fine with the maximized figure window, right until I load an image and display it, using imshow or image command - then the figure window resizes to fit the image. I could maximize it back, but that causes some disturbing motion of the window frame.
How can I keep the window maximized, and display an image at 1:1 ratio (not scaled to fit a maximized window), so one pixel in the image fits no more/less than one "pixel" on screen?
Below is an example of what I have now (using 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);
% creating a handle for imshow, hiding it for now
img = imread('musik.png');
hImshow = imshow(img);
set(hImshow,'Visible','off');
% Show the image
% This is where Matlab decides to modify the figure window,
% so it fits the image rather than staying maximized.
set(hImshow,'Visible','on');
% How can I display an image in an existing-and-maximized figure
% window, so that the window remains maximized, and the image
% is displayed at actual size (not scaled), so one pixel in the
% image is displayed by one "pixel" on the monitor?
Best regards, Christian
採用された回答
その他の回答 (2 件)
Image Analyst
2013 年 11 月 14 日
編集済み: Image Analyst
2022 年 8 月 3 日
Issue this command right after you call imshow():
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
You can now (after R2014b I believe) do it this way instead:
g = gcf;
g.WindowState = 'maximized';
2 件のコメント
Walter Roberson
2015 年 6 月 14 日
sara commented "Great"
Muhammad Ghani
2022 年 8 月 3 日
awesome
C
2013 年 11 月 14 日
0 投票
1 件のコメント
Image Analyst
2013 年 11 月 14 日
That would be nice. Sorry but I don't know of any other way.
カテゴリ
ヘルプ センター および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!