matlab函数之saveas 和imwrite

文章来源:http://blog.sina.com.cn/u/1890825127 

saveas(handle,['目录','文件名'])  
如果只有一幅图,handle设为gcf
如果有多副,handle需单独设置


imwrite(image_data,['directory','filename'])
需要与getframe连用


两个命令都可以用来保存图像,区别在于
1、背景色:saveas保存的图像 背景色自动设置为白色,imwrite保存图像为所见即所得
2、图像大小: saveas无视你设置的图像大小,按默认保存,imwrite保存所见即所得


contrast example:在当前目录下image文件夹下找到两个图像,对比一下


clear
clc
x=0:pi/100:2*pi;
y=sin(x);
h=plot(x,y);  % h为plot线的句柄handle
set(gcf,'position',[80,100,400,600])
% 将图像设置为距屏幕左下角 [80,100]像素
% 图像大小设置为400*600像素
set(gcf,'color',[1,1,1]) % 背景色设置为白色
mkdir image 
% 在当前文件夹下新建image文件夹,如果已存在会warning,不影响运行


% ========================
saveas(gcf,['image','test1.jpg'])


% ========================
f=getframe(gcf);
imwrite(f.cdata,['image','test2.jpg'])

你可能感兴趣的:(matlab函数)