Info

此问题已关闭。 请重新打开它进行编辑或回答。

hey, help me fix my problem on save image .

2 次查看(过去 30 天)
fatin rasyidah
fatin rasyidah 2017-10-28
关闭: MATLAB Answer Bot 2021-8-20
hi, i've try code suggested by Image Analyst on someone's question about how to save image. but when i've try the code , i got an error . how can i fix the error . here are the code. please help me. thanks in advance :)
function pushbutton7_Callback(hObject, eventdata, handles)
global bw; startingFolder = userpath defaultFileName = fullfile(startingFolder, '*.*'); [baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file'); if baseFileName == 0 % User clicked the Cancel button. return; end fullFileName = fullfile(folder, baseFileName) imwrite(bw, fullFileName);
*bw is the result that i want to save.

回答(1 个)

Jan
Jan 2017-10-28
The error message is clear: The contents of the variable bw is an empty array, but imwrite cannot write images without pixels.
I guess, the reason is in the part of the code, which should assign a value to the global variable bw. This is a typical effect of using global variables: They are hard to debug and tend to cause bugs. Perhaps any other function has overwritten the global bw by accident? Therefore it is recommended, to avoid them carefully. Better store bw in the ApplicationData of the figure, e.g. by using guidata:
% In the function where bw is calculated:
handles.bw = bw;
guidata(hObject, handles);
Then in your function use handles.bw and remove the global variables.
  2 个评论
fatin rasyidah
fatin rasyidah 2017-10-28
sorry, since i am very beginning with this matlab. i dont know what are the use of "handles"? and how to use it ? could u explain a little bit to me ?
Jan
Jan 2017-11-2
"handles" is a struct, which is provided to all callbacks. This allows to share data between the callbacks.
Do not confuse the "handles" struct with handles of graphic elements like figures or uicontrol. Each graphic object has a unique "handle", a kind of address to access its contents. The handles of the GUI elements are stored in the "handles" struct, if you use GUIDE, but I'm convinced that this name is more confusing.

此问题已关闭。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by