matlab GUI saves images on axes (coordinates)

1. Default way

The save image of the matlab GUI default menu defaults to keep the full GUI, including using "Menu->Edit->Copy Graphics".

2 Save the visible area

2.1 Code

[FileName,PathName] = uiputfile({'*.jpg','JPEG(*.jpg)';...
                                             '*.bmp','Bitmap(*.bmp)';...
                                             '*.gif','GIF(*.gif)';...
                                             '*.*',  'All Files (*.*)'},...
                                             'Save Picture','Untitled');
if FileName==0
      disp('保存失败');
      return;
else
      h=getframe(picture);%picture是GUI界面绘图的坐标系句柄
      imwrite(h.cdata,[PathName,FileName]);
end           

2.2 Description

The function getframe() is to obtain a frame of image in the coordinate axis, and the returned object has two members, cdata and colormap.

2.3 Effects

save visible area

3 Save the area with the axes

3.1 Code

new_f_handle=figure('visible','off');
new_axes=copyobj(picture,new_f_handle); %picture是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);

3.2 Description

In fact, a new coordinate graph is created, the GUI is copied to the new image, the new image is output, and finally the newly created graph handle is deleted.

3.3 Effects

save area with axes

references

  • guopanfeng
  • Chris_Lee's blog was
    written in a hurry, and some of the referenced web pages could not be found. Please forgive me for colleagues who are committed to sharing.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325126218&siteId=291194637