How to save image in database
1 view (last 30 days)
Show older comments
hi, i try insert image in database together with sting information about image but always got error. Maybe you know how to solve that. Error: Error using cell2mat (line 46) All contents of the input cell array must be of the same data type.
Error in pildymas>pushbutton2_Callback (line 301) exdata = {vardas,pavarde,laipsnis,pareigos,telefonas,marke,numeris,tarnyba, cell2mat(nuotrauka)};
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in pildymas (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)pildymas('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.jpg','*.bmp'},'File Selector');
image1 = imread(strcat(pathname, filename));
axes(handles.axes1);
I = imshow(image1);
guidata(hObject,handles)
% save the updated handles object
% 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');
I = handles.I(:)'; % transpose it
I = im2uint8(I); % convert it to uint8
s = dec2hex(I, 2)'; % convert it to hexcode
image_str = s(:)';
clear I s
nuotrauka = {[1],'.jpg',image_str,[42],[42]}; % define the input data
exdata = {vardas,pavarde,laipsnis,pareigos,telefonas,marke,numeris,tarnyba, cell2mat(nuotrauka)};
fastinsert(conn, 'info', {'vardas','pavarde','laipsnis','pareigos','telefonas','marke','numeris','tarnyba','nuotrauka'},exdata)
guidata(hObject, handles);
close(conn);
thanks in advise
Answers (0)
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!