0

我想保存指定轴的图像。我不断收到You may not have permission to write错误。这是我保存为按钮的代码:

axes(handles.axes3);
[FileName, PathName] = uiputfile('*bmp', 'Save As');
Name = fullfile(FileName, PathName);
imwrite(handles.TReg, Name, 'bmp');

此外,handles.TReg是在另一个函数上定义的变换图像。

我似乎在这里找不到我的错误,任何想法都将不胜感激。

编辑 如果我使用代码:

axes(handles.axes3);
[FileName, PathName] = uiputfile('*bmp', 'Save As');
Name = fullfile(FileName, PathName);
imwrite(handles.TReg, 'Name', 'bmp');

该文件将在正确的目录中另存为 Name.bmp。但是我确实注意到,当我尝试使用原始代码保存时,错误也会显示(我错过了这一点,抱歉):

Can't open file "Image1\C:\Users\Shinobii\Documents\MATLAB\" for writing.

我认为路径名应该像

"C:\Users\Shinobii\Documents\MATLAB\Image1"

这可能是问题吗?

4

3 回答 3

2

小错误:

[FileName, PathName] = uiputfile('*.bmp', 'Save As'); %# <-- dot
Name = fullfile(PathName,FileName);  %# <--- reverse the order of arguments
imwrite(img, Name, 'bmp');

检查用户是否没有取消对话框也是一个好主意:

[FileName, PathName] = uiputfile('*.bmp', 'Save As');
if PathName==0, return; end    %# or display an error message
于 2012-07-26T18:18:32.593 回答
1

检查路径和文件名,并尝试通过手动调用 imwrite 来保存图像。这可能与 GUI 和按钮回调无关,但与文件权限和/或路径名无关。

于 2012-07-26T14:54:40.513 回答
0

再一次,这似乎是一个我应该早点发现的愚蠢错误。

axes(handles.axes3);
[FileName, PathName] = uiputfile('*bmp', 'Save As');
Name = fullfile(PathName, FileName);
imwrite(handles.TReg, Name, 'bmp');

Name我需要翻转FileNameand PathName

谢谢你的帮助!

于 2012-07-26T18:18:09.850 回答