在matlab中保存GUI特定区域的图像

在matlab中保存GUI特定区域的图像,matlab,user-interface,matlab-figure,matlab-guide,Matlab,User Interface,Matlab Figure,Matlab Guide,我已经开发了一个GUI,它可以浏览mat文件并在matlab中绘制绘图。现在,我想使用GUI中的“保存”按钮将这些绘图保存为图像 我做了将回调函数另存为的编码 [file,path]=uiputfile({'*.bmp','BMP'},'Save Image As'); f=getframe(handles.axes); [x,map]=frame2im(f); imwrite(x,fullfile(path, file),'bmp'); 但这段代码只给出了一个没有轴标记的图 有人建议我使用

我已经开发了一个GUI,它可以浏览mat文件并在matlab中绘制绘图。现在,我想使用GUI中的“保存”按钮将这些绘图保存为图像

我做了将回调函数另存为的编码

[file,path]=uiputfile({'*.bmp','BMP'},'Save Image As');
f=getframe(handles.axes);
[x,map]=frame2im(f); 
imwrite(x,fullfile(path, file),'bmp');
但这段代码只给出了一个没有轴标记的图

有人建议我使用
explore\u fig
,但我无法将其用于我的目的

如果我想将GUI的特定区域保存为图像,我应该使用什么代码


谢谢,正如您所注意到的,使用它只会获取轴的内容,而不会更多。为了获得标记的轴,可以利用轴的特性查找轴的边界矩形。
tighinset
是添加到轴
位置的边距,为标签留出空间

此外,您还可以利用
getframe
的第二个输入,该输入指定要获取的rect(以像素为单位)。您可以使用
hgconvertunits
(未记录)计算此值

如果我们在一些样本数据上这样做

% 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;
原作是这样的

带有rect的
getframe
的结果是


正如您所注意到的,使用它只会抓取轴的内容,而不会更多。为了获得标记的轴,可以利用轴的特性查找轴的边界矩形。
tighinset
是添加到轴
位置的边距,为标签留出空间

此外,您还可以利用
getframe
的第二个输入,该输入指定要获取的rect(以像素为单位)。您可以使用
hgconvertunits
(未记录)计算此值

如果我们在一些样本数据上这样做

% 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;
原作是这样的

带有rect的
getframe
的结果是