Gui Screen Shot Button
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Christopher
il 9 Nov 2014
Commentato: Kiarash Ahi
il 4 Mar 2018
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 Commento
Geoff Hayes
il 10 Nov 2014
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?
Risposta accettata
Image Analyst
il 10 Nov 2014
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)
3 Commenti
Image Analyst
il 13 Nov 2014
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.
Più risposte (1)
Kiarash Ahi
il 3 Mar 2018
Modificato: Kiarash Ahi
il 3 Mar 2018
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 Commenti
Image Analyst
il 4 Mar 2018
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
il 4 Mar 2018
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
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!