Gui Screen Shot Button

2 visualizaciones (últimos 30 días)
Christopher
Christopher el 9 de Nov. de 2014
Comentada: Kiarash Ahi el 4 de Mzo. de 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 comentario
Geoff Hayes
Geoff Hayes el 10 de Nov. de 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?

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 10 de Nov. de 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)
Then use fullFileName instead of "Sections" in saveas(), or better yet export_fig.
  3 comentarios
Image Analyst
Image Analyst el 13 de Nov. de 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.
Christopher
Christopher el 13 de Nov. de 2014
Editada: Christopher el 14 de Nov. de 2014
Update, Export_fig works perfectly. Image Analyst, thanks for all your help :)

Iniciar sesión para comentar.

Más respuestas (1)

Kiarash Ahi
Kiarash Ahi el 3 de Mzo. de 2018
Editada: Kiarash Ahi el 3 de Mzo. de 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 comentarios
Image Analyst
Image Analyst el 4 de Mzo. de 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
Kiarash Ahi el 4 de Mzo. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by