user interface - Saving image of specific area of GUI in matlab -


i have devloped gui browses mat files , draw plots in matlab want save these plots images using save button in gui

i did coding of save callback function as

[file,path]=uiputfile({'*.bmp','bmp'},'save image as'); f=getframe(handles.axes); [x,map]=frame2im(f);  imwrite(x,fullfile(path, file),'bmp'); 

but code gives me graph without axis labelled.

someone suggested me use explore_fig unable use purpose

if want save specific area of gui image code should use

thanks

as have noticed, using getframe grabs solely contents of axes , no more. in order axes labeled, can take advantage of tightinset property of axes find bounding rectangle of axes. tightinset margin added axes position make room labels.

also, can take advantage of second input getframe specifies rect (in pixels) grab. can compute using hgconvertunits (undocumented).

% position including labels/ticks position = get(hax, 'position'); inset = get(hax, 'tightinset'); outerpos = [position(1:2) - inset(1:2), position(3:4) + inset(3:4)];  % ensure units pixels rect = hgconvertunits(hfig, outerpos, get(hax1, 'units'), 'pixels', hfig);  % grab specified rectangle figure im = getframe(hfig, rect); 

if on sample data

% load sample data load mri img = squeeze(d(:,:,12));  % display axes in middle of figure hfig = figure(); hax = axes('position', [0.2 0.2 0.5 0.5]); imagesc(img); xlabel('columns'); ylabel('rows'); axis image; 

the original looks this

enter image description here

and result of getframe rect is

enter image description here


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -