Azzera filtri
Azzera filtri

How to use image with two push buttons?

1 visualizzazione (ultimi 30 giorni)
Gytis Raudonius
Gytis Raudonius il 21 Mag 2017
Commentato: Gytis Raudonius il 28 Mag 2017
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.

Risposte (1)

Image Analyst
Image Analyst il 21 Mag 2017
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 Commento
Gytis Raudonius
Gytis Raudonius il 28 Mag 2017
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?

Accedi per commentare.

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by