getframe

来源:互联网 发布:32k单片机 编辑:程序博客网 时间:2024/06/11 08:16
clear;clc;clf;
x=0:pi/100:2*pi;
y=sin(x);
plot(x,y)
set(gcf,'color',[1 1 1]) %设置背景色为白色
title('测试图像保存')
F=getframe(gcf); % 获取整个窗口内容的图像
F1=getframe; % 获取坐标轴为界的图像
imwrite(F.cdata,'test1.png')
imwrite(F1.cdata,'test2.png')
=======================
getframe获得的是一个架构struct类型的数据,
其中cdata子域的内容才可以用imwrite内容保存,用F.cdata表示
getframe(gcf) 即get current figure,获得窗口内图像,包含lege
为gca(get current axis)。
imwrite 可以保存jpg、png等格式图像,gif是7.0添加的,但是好像
与在图像界面直接利用复制,或用file>save as...保存不同的是,
(RGB表示为[.7 .7 .7]),若想保留白色背景图,需添加例子中的
=====================================================

保存多个图像时,顺序命名图像文件名称需用到 num2str 或 sprint

clear;clc;clf;
x=0:pi/100:2*pi;
y=sin(x);
plot(x,y)
set(gcf,'color',[1 1 1]) %设置背景色为白色
title('测试图像保存')
F=getframe(gcf); % 获取整个窗口内容的图像
F1=getframe; % 获取坐标轴为界的图像
imwrite(F.cdata,'test1.png')
imwrite(F1.cdata,'test2.png')
=======================
getframe获得的是一个架构struct类型的数据,
其中cdata子域的内容才可以用imwrite内容保存,用F.cdata表示
getframe(gcf) 即get current figure,获得窗口内图像,包含lege
为gca(get current axis)。
imwrite 可以保存jpg、png等格式图像,gif是7.0添加的,但是好像
与在图像界面直接利用复制,或用file>save as...保存不同的是,
(RGB表示为[.7 .7 .7]),若想保留白色背景图,需添加例子中的
=====================================================
保存多个图像时,顺序命名图像文件名称需用到 num2str 或 sprint



0 0