How to use image with two push buttons?

2 次查看(过去 30 天)
Hi, everyone have problem programing in guide, so in guide i opened image with file selector in this i use pushbutton1, so now i want so save this image into database using pushbutton2, always got error on : Undefined function or variable 'image_str'.
Error in pildymas>pushbutton2_Callback (line 291) nuotrauka = {[1],'.jpg',image_str,[42],[42]};
add code below:
function pushbutton1_Callback(hObject, eventdata, handles)
% conn = database('baze', 'root', 'root', 'Vendor', 'MYSQL', 'Server', 'localhost', 'PortNumber', 3306);
% setdbprefs('DataReturnFormat','cellarray');
[filename, pathname] = uigetfile({'*.jpg','*.bmp'},'File Selector');
image1 = imread(strcat(pathname, filename));
axes(handles.axes1);
I = imshow(image1);
guidata(hObject,handles);
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
%Use handles structure to recall the selected file
conn = database('baze', 'root', 'root', 'Vendor', 'MYSQL', 'Server', 'localhost', 'PortNumber', 3306);
setdbprefs('DataReturnFormat','cellarray');
vardas = get(handles.edit1, 'string');
pavarde = get(handles.edit2, 'string');
laipsnis = get(handles.edit3, 'string');
pareigos = get(handles.edit4, 'string');
telefonas = get(handles.edit5, 'string');
marke = get(handles.edit6, 'string');
numeris = get(handles.edit7, 'string');
tarnyba = get(handles.edit8, 'string');
fid = fopen('tempfile.fig', 'r')
I = fread(fid, inf, '*uint8')
fclose(fid)
s = size(I);
nuotrauka = reshape(I,[],1);
exdata = {vardas,pavarde,laipsnis,pareigos,telefonas,marke,numeris,tarnyba,nuotrauka};
fastinsert(conn, 'info', {'vardas','pavarde','laipsnis','pareigos','telefonas','marke','numeris','tarnyba','nuotrauka'},exdata)
close(conn);
thanks in advise.

回答(1 个)

Image Analyst
Image Analyst 2017-5-21
Don't force your users to interact with a dialog box to open an image. Make it easy for them and put all the images into a listbox so they can click on and display the one they want. See MAGIC for an easy way to do that: http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component
If you still want to make it more difficult for your users (and use a "file open" dialog box instead of an easy listbox), then you can still call uigetfile(), but you need to make the variable known to your other functions. The FAQ shows several ways of doing that. http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
  1 个评论
Gytis Raudonius
Gytis Raudonius 2017-5-28
I little change code, and it workks but when i want to retrive info with name last name etc. and image , i get all information about driver but dont get image. Where is problem?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by