How can I save a GUI window in Matlab(e.g. as png)? -


i created gui inside matlab;

to make easy understandable let's there static , non static textfield , 1 push button

in nonstatic text field 1 can enter number , pressing push button answer in static text field, let's 2*a answer;

now want have screenshot of gui there can see number in non static field , result in static text field; how shown after pressing button...

how can achieve that?

thanks in advance.. :)

ok it's more simple thought , thescreencapture option might overkill in situation.

what need getframe function, captures content of axes or figure of choice, here gui.

here code simple example can copy , paste. upon pressing button, new window appears content of gui. can replace part of code call imwrite save image in png format. useful code is:

%// capture content of current figure f = getframe(gcf); 

the image data stored in cdata property of structure f, can save eg with.

%// imwrite(f.cdata,...) 

so whole code following:

function testgui clc  hfigure  = figure('position',[300 300 300 100],'units','normalized','name','myfigure');  handles.edit1= uicontrol('style','edit','string','','position',[40 50 50 30]); handles.edit2= uicontrol('style','edit','string','','position',[100 50 50 30]); handles.snapshot= uicontrol('style','push','string','snapshot','position',[160 50 70 30],'callback',@(s,e) snapshot_callback);  guidata(hfigure,handles);  %// callback button 1     function snapshot_callback         handles = guidata(hfigure);          %// double entry edit box 1. (do whatever want)                  x = str2double(get(handles.edit1,'string'));          newx = 2*x;         set(handles.edit2,'string',newx);          %// take screenshot!         f = getframe(gcf);          figure()         imshow(f.cdata); %// image data in f.cdata. can replace imwrite(f.cdata,...)          %// update handles structure.         guidata(hfigure,handles);     end end 

and screenshot computer: on left initial gui , on right new figure generated content of gui.

enter image description here


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -