【问题标题】:MATLAB save image from GUI using push buttonMATLAB使用按钮从GUI保存图像
【发布时间】:2012-07-26 14:45:17
【问题描述】:

我想保存指定轴的图像。我不断收到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"

这可能是问题吗?

【问题讨论】:

    标签: matlab user-interface


    【解决方案1】:

    小错误:

    [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
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我已编辑我的问题以包含有关错误的更多信息。
      【解决方案3】:

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

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

      Name 中,我需要翻转FileNamePathName

      感谢您的帮助!

      【讨论】:

      • 抱歉,Georg,我有一段时间没有使用计算机了。 Amro 是一位圣人,他总是有答案!
      猜你喜欢
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2017-04-24
      • 2018-04-09
      • 1970-01-01
      • 2016-07-31
      • 1970-01-01
      • 2011-12-19
      相关资源
      最近更新 更多