Gui Screen Shot Button

조회 수: 2 (최근 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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by