matlab gui界面做了一个图像显示的功能,如何把显示图像保存为一个文件

我做了一个简单的GUI界面,可以绘图,如何把显示出来的图像通过一个按钮点击,进行保存。同时可以定义文件位置和文件名称?callback函数应该怎么写?

做一个保存按钮,Tag是“save”
callback函数如下

% --- Executes on button press in save.
function save_Callback(hObject, eventdata, handles)
% hObject handle to save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uiputfile({'*.bmp';'*.jpg';'*.png'}, 'Pick an image-file');
if isequal(filename,0) || isequal(pathname,0)
disp('User pressed cancel')
return
else
disp(['User selected ', fullfile(pathname, filename)])
end
imwrite(handles.tempimg,[pathname filename]);%%你要保存的图像的axes名称
guidata(hObject, handles);
温馨提示:答案为网友推荐,仅供参考
相似回答