matlab GUI 界面,保存图片的程序如下,保存文件夹里已经有相同名字的图片存在了,为什么不提醒是否替换
button1=questdlg('是否保存图片?','','是','否','是');ifstrcmp(button1,'是')axes(handles.axes1);n...
button1=questdlg('是否保存图片?',' ','是','否','是');
if strcmp(button1,'是')
axes(handles.axes1);
newfig=figure;
set(newfig,'visible','off');
newaxes=copyobj(handles.axes1,newfig);
set(newaxes,'units','default','position','default');
[filename,pathname]=uiputfile({'*.bmp','BMP files';'*.jpg','JPG files'},'保存图像','图片1');
if isequal(filename,0)||isequal(pathname,0)
return;
else
fpath=fullfile(pathname,filename);
newf=getframe(newfig);
f=frame2im(newf);
imwrite(f,fpath,'jpg');
close(newfig);
end
end 展开
if strcmp(button1,'是')
axes(handles.axes1);
newfig=figure;
set(newfig,'visible','off');
newaxes=copyobj(handles.axes1,newfig);
set(newaxes,'units','default','position','default');
[filename,pathname]=uiputfile({'*.bmp','BMP files';'*.jpg','JPG files'},'保存图像','图片1');
if isequal(filename,0)||isequal(pathname,0)
return;
else
fpath=fullfile(pathname,filename);
newf=getframe(newfig);
f=frame2im(newf);
imwrite(f,fpath,'jpg');
close(newfig);
end
end 展开
1个回答
展开全部
使用这个代码可以实现:
[filename pathname]=uiputfile({'*.jpeg','jpg file(*.jpg)');
str = [pathname filename];
strBefore = str(1:end-4);
strEx = str(end-3 : end);
figure('visible', 'off');
strcmp(strEx, '.jpg')
fullName = [strBefore,'.jpg'];
h=get(handles.axes1,'children');
figure('visible','off');
axes;
copyobj(h,gca)
print(gcf,'-dmeta',fullName)
[filename pathname]=uiputfile({'*.jpeg','jpg file(*.jpg)');
str = [pathname filename];
strBefore = str(1:end-4);
strEx = str(end-3 : end);
figure('visible', 'off');
strcmp(strEx, '.jpg')
fullName = [strBefore,'.jpg'];
h=get(handles.axes1,'children');
figure('visible','off');
axes;
copyobj(h,gca)
print(gcf,'-dmeta',fullName)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询