自己创建GUI后,处理后的图像显示在axes,或者是plot后的图显示在axes中希望保存此图像,一个方法就是截屏,一般就是用qq截屏或者print screen,这些截屏有一个缺点:图像周围有一条黑色的矩形框,虽然很细,但是看着也不爽……于是下面说明一下GUI中的axes的图像怎么保存:
假设你的GUI界面中有一个按钮,点击此按钮时,就保存你的plot图像,于是可以在你的按钮Callback函数中添加如下的代码:
new_f_handle=figure('visible','off');
new_axes=copyobj(handles.axes3,new_f_handle); %axes1是GUI界面绘图的坐标系
set(new_axes,'units','default','position','default');
[filename,pathname fileindex]=uiputfile({'*.jpg';'*.bmp'},'save picture as');
if ~filename
return
else
file=strcat(pathname,filename);
switch fileindex %根据不同的选择保存为不同的类型
case 1
print(new_f_handle,'-djpeg',file);
case 2
print(new_f_handle,'-dbmp',file);
end
end
delete(new_f_handle);
保存成功……
如我保存的图像如下:
Matlab的GUI中的axes中图像的保存方法