How to save image in database

조회 수: 1 (최근 30일)
Gytis Raudonius
Gytis Raudonius 2017년 5월 27일
댓글: Selva Karna 2017년 8월 17일
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
  댓글 수: 1
Selva Karna
Selva Karna 2017년 8월 17일
use imwrite or mat save

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by