Gui Screen Shot Button

8 ビュー (過去 30 日間)
Christopher
Christopher 2014 年 11 月 9 日
コメント済み: Kiarash Ahi 2018 年 3 月 4 日
Hello all,
I have a GUI that i created using guide and I am trying to create a push button that can be used to save a screen shot of the GUI window. I want to be able to select the location it is saving to and have it same with the same resolution. I got it working using the saveas function, but it saves, but the images come out very low quality. The save as code is as follows:
function pushbutton1_Callback(hObject, eventdata, handles)
[name,path,index] = uiputfile
saveas(Sections,[path name],'jpg');
I am not sure if there is a way to do this with the print command or not, but any help is appreciated.
  1 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 11 月 10 日
Christopher - how are you creating Sections which is presumably the screen shot of your GUI? It could be that the resolution is low quality since you are saving this image to jpeg. Have you tried bmp or other formats?

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2014 年 11 月 10 日
Try this snippet to get a valid filename.
% Note, if you're saving an image you can use imsave() instead of uiputfile().
startingFolder = userpath
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
Then use fullFileName instead of "Sections" in saveas(), or better yet export_fig.
  3 件のコメント
Image Analyst
Image Analyst 2014 年 11 月 13 日
Nothing - you don't use it. The first argument is the full file name - that's why I called it that. It's the drive, folder, basefilename, and extension all in one single string as the second argument. The handle is the first argument.
Christopher
Christopher 2014 年 11 月 13 日
編集済み: Christopher 2014 年 11 月 14 日
Update, Export_fig works perfectly. Image Analyst, thanks for all your help :)

サインインしてコメントする。

その他の回答 (1 件)

Kiarash Ahi
Kiarash Ahi 2018 年 3 月 3 日
編集済み: Kiarash Ahi 2018 年 3 月 3 日
I put it like this, but did not work, could you please help me:
function pushbutton76_Callback(hObject, eventdata, handles)
% Note, if you're saving an image you can use imsave() instead of uiputfile().
startingFolder = userpath
defaultFileName = fullfile(startingFolder, 'scsh.jpg')
saveas(Sections,[path name],'jpg');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
  2 件のコメント
Image Analyst
Image Analyst 2018 年 3 月 4 日
Try this:
% Get the name of the file that the user wants to save.
% Note, if you're saving an image you can use imsave() instead of uiputfile().
startingFolder = pwd % Or "userpath" or wherever you want.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
saveas(Sections, fullFileName);
The thing though is that you need to get the variable Sections in to that function. For that, see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
Kiarash Ahi
Kiarash Ahi 2018 年 3 月 4 日
I fixed it like this, it also keeps the resolution to what you see on your screen:
function pushbutton76_Callback(hObject, eventdata, handles)
% Note, if you're saving an image you can use imsave() instead of uiputfile().
matlab.graphics.internal.setPrintPreferences('DefaultPaperPositionMode','auto')
CHEA=handles.CHEA;
fig = gcf;
fig.PaperPositionMode = 'auto';
print('ScreenSizeFigure','-dpng','-r0')
startingFolder = userpath
global num;
n=num;
%s
ch=char(CHEA(n,1))
n=num2str(n)
n=char(n)
ch=strcat(ch,'-',n,'.png')
%ch=fprintf('%s',CHEA(n,1))
defaultFileName = fullfile(startingFolder,ch)
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
saveas(gca,defaultFileName,'png');
fig.PaperPositionMode = 'auto';
print('ScreenSizeFigure','-dpng','-r0')
if baseFileName == 0
% User clicked the Cancel button.
return;
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeManage Products についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by