INSERT AND READ IMAGE IN BLOB DATABASE
INSERT AND READ IMAGE IN BLOB DATABASE
Boa tarde, meu caso é o seguinte, já tentei de varias formas inserir uma imagem num campo blob (banco MYSQL) e depois ler, e não consigo.
O maximo que consegui foi salva-la, porém não sei se ficou no formato correto.
Preciso salvar imagem JPG no banco e depois recupera-la, qual a maneira mais simples de se fazer isso?
preciso de um exemplo
sorry for bad english
im using mydac 8.6
O maximo que consegui foi salva-la, porém não sei se ficou no formato correto.
Preciso salvar imagem JPG no banco e depois recupera-la, qual a maneira mais simples de se fazer isso?
preciso de um exemplo
sorry for bad english
im using mydac 8.6
Re: INSERT AND READ IMAGE IN BLOB DATABASE
You can use our MyDacDemo project. On the 'General Demos\Pictures' tab, there is demonstrated writing and reading graphic files to\from the database. This project can be found in the 'Demos\MyDacDemo' folder of the MyDAC demo projects installation directory.
Please write your question in English.
Please write your question in English.
Re: INSERT AND READ IMAGE IN BLOB DATABASE
Good afternoon, my case is this , I've tried in many ways to insert a picture into a blob field (MYSQL database ) and then read , and I can not .
The maximum I got was save her , but do not know if it was the correct format.
I must save JPG image in the bank and then retrieve it , which the simplest way of doing this ?
I need an example
sorry for bad Inglês
im using MyDAC 8.6
( I do not know why the question appeared in Portuguese , I translated correctly)
The maximum I got was save her , but do not know if it was the correct format.
I must save JPG image in the bank and then retrieve it , which the simplest way of doing this ?
I need an example
sorry for bad Inglês
im using MyDAC 8.6
( I do not know why the question appeared in Portuguese , I translated correctly)
Re: INSERT AND READ IMAGE IN BLOB DATABASE
Hello , my demo directory of the picture seems to be in trouble, the Delphi does not open the form so I can not see how the operation .
Re: INSERT AND READ IMAGE IN BLOB DATABASE
Well, come on , I managed to open the project here understand, but do not apply too much. You see, I am developing for mobile, I carry a picture in a TImage (either the library or direct the camera) , this photo loaded in Timagem I need to go to the database, can not use DIALOGS , only the picture loaded . below is my insert.
qenvia_ocorrencia := TMyQuery.Create(nil);
qenvia_ocorrencia.Connection := datamodule3.MyConnection1;
qenvia_ocorrencia.SQL.Clear;
qenvia_ocorrencia.SQL.Add('INSERT INTO SOLICITACOES (protocolo, status, data, hora, ocorrencia, rua, numero, bairro, cep, link_maps,obs,movimentacao,imagem, cod_usuario)');
qenvia_ocorrencia.SQL.Add('VALUES (:protocolo, :status, :data, :hora, :ocorrencia, :rua, :numero, :bairro, :cep, :link_maps,:obs,:movimentacao, :imagem, :cod_usuario)');
qenvia_ocorrencia.ParamByName('PROTOCOLO').AsString := '10'; //pegar o ultimo protocolo
qenvia_ocorrencia.ParamByName('STATUS').AsString := 'TESTE';
qenvia_ocorrencia.ParamByName('DATA').AsDate := DATE;
qenvia_ocorrencia.ParamByName('HORA').AsDateTime := TIME;
qenvia_ocorrencia.ParamByName('OCORRENCIA').AsString := texto_listbox;
qenvia_ocorrencia.ParamByName('RUA').AsString := edtRua.Text;
qenvia_ocorrencia.ParamByName('NUMERO').AsInteger := StrToInt(edtNumero.Text);
qenvia_ocorrencia.ParamByName('BAIRRO').AsString := edtBairro.Text;
qenvia_ocorrencia.ParamByName('CEP').AsString := edtCep.Text;
qenvia_ocorrencia.ParamByName('LINK_MAPS').AsString := edtUrl.Text;
qenvia_ocorrencia.ParamByName('OBS').AsString := memDetalhes.Text;
qenvia_ocorrencia.ParamByName('MOVIMENTACAO').AsString := 'TRAMITADO';
qenvia_ocorrencia.ParamByName('IMAGEM').LoadFromStream(imgfoto ftBlob);
qenvia_ocorrencia.ParamByName('COD_USUARIO').AsInteger := ufrmInicial.codigo_usuario_global;
qenvia_ocorrencia.Execute;
qenvia_ocorrencia := TMyQuery.Create(nil);
qenvia_ocorrencia.Connection := datamodule3.MyConnection1;
qenvia_ocorrencia.SQL.Clear;
qenvia_ocorrencia.SQL.Add('INSERT INTO SOLICITACOES (protocolo, status, data, hora, ocorrencia, rua, numero, bairro, cep, link_maps,obs,movimentacao,imagem, cod_usuario)');
qenvia_ocorrencia.SQL.Add('VALUES (:protocolo, :status, :data, :hora, :ocorrencia, :rua, :numero, :bairro, :cep, :link_maps,:obs,:movimentacao, :imagem, :cod_usuario)');
qenvia_ocorrencia.ParamByName('PROTOCOLO').AsString := '10'; //pegar o ultimo protocolo
qenvia_ocorrencia.ParamByName('STATUS').AsString := 'TESTE';
qenvia_ocorrencia.ParamByName('DATA').AsDate := DATE;
qenvia_ocorrencia.ParamByName('HORA').AsDateTime := TIME;
qenvia_ocorrencia.ParamByName('OCORRENCIA').AsString := texto_listbox;
qenvia_ocorrencia.ParamByName('RUA').AsString := edtRua.Text;
qenvia_ocorrencia.ParamByName('NUMERO').AsInteger := StrToInt(edtNumero.Text);
qenvia_ocorrencia.ParamByName('BAIRRO').AsString := edtBairro.Text;
qenvia_ocorrencia.ParamByName('CEP').AsString := edtCep.Text;
qenvia_ocorrencia.ParamByName('LINK_MAPS').AsString := edtUrl.Text;
qenvia_ocorrencia.ParamByName('OBS').AsString := memDetalhes.Text;
qenvia_ocorrencia.ParamByName('MOVIMENTACAO').AsString := 'TRAMITADO';
qenvia_ocorrencia.ParamByName('IMAGEM').LoadFromStream(imgfoto ftBlob);
qenvia_ocorrencia.ParamByName('COD_USUARIO').AsInteger := ufrmInicial.codigo_usuario_global;
qenvia_ocorrencia.Execute;
Re: INSERT AND READ IMAGE IN BLOB DATABASE
To load graphic files like JPEG in a Blob field, you can use the following code:
To load data from the Blob field to the TImage component, use the following code:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var
BlobStream: tStream;
Surf: TBitmapSurface;
begin
if Image1 <> nil then
begin
Surf := TBitmapSurface.Create;
Surf.Assign(Image1.Bitmap);
BlobStream := TMemoryStream.Create;
if not TBitmapCodecManager.SaveToStream(BlobStream, Surf, '.jpg') then
raise EBitmapSavingFailed.Create('No');
BlobStream.Position := 0;
myquery2.ParamByName('imagem').LoadFromStream(BlobStream, ftBlob);
myquery2.ExecSQL;
Surf.Free;
end;
end;
Code: Select all
procedure TForm1.Button2Click(Sender: TObject);
var
BlobStream: TStream;
begin
BlobStream := TMemoryStream.Create;
myquery1.GetBlob(myQuery1.FieldByName('imagem')).SaveToStream(BlobStream);
Blobstream.Position := 0;
Image2.bitmap.loadfromstream(blobstream);
BlobStream.Free;
end;
Re: INSERT AND READ IMAGE IN BLOB DATABASE
Friend, grateful for the response, I think we're on the road , but only look at the picture, there is no such TBitmapSurface or would have to use some special Unit ? I will replace TBitmapSurface by TBitmap but not saved the photo on the bench.
Re: INSERT AND READ IMAGE IN BLOB DATABASE
I think the problem was to declare that library : FMX.Surfaces
I think I could save the image , because the bank already has a string in the field ..
In TImage I used the " picture" before the bitmap is a bitmap for picute class " Image1.Picture.Bitmap.loadfromstream ( blobstream ) ; "
To compile and run the function of the following error:
Bitmap image is not valid .
I think I could save the image , because the bank already has a string in the field ..
In TImage I used the " picture" before the bitmap is a bitmap for picute class " Image1.Picture.Bitmap.loadfromstream ( blobstream ) ; "
To compile and run the function of the following error:
Bitmap image is not valid .
Re: INSERT AND READ IMAGE IN BLOB DATABASE
.. In the VCL you would do
Image1.Picture.Bitmap.LoadFromStream(lStream);
In FMX you do
Image1.Bitmap.LoadFromStream(lStream);
Image1.Picture.Bitmap.LoadFromStream(lStream);
In FMX you do
Image1.Bitmap.LoadFromStream(lStream);
Last edited by Dacuser on Tue 06 Oct 2015 20:45, edited 1 time in total.
Re: INSERT AND READ IMAGE IN BLOB DATABASE
Hello friend, to burn the image I am using a client for android and IOS , the recording seems to be working .
below follows the string written to the blob :
I'm trying to read in VCL windows32 and appears the image below:
Codigo:
I'm using Delphi XE 10 Seattle
below follows the string written to the blob :
I'm trying to read in VCL windows32 and appears the image below:
Codigo:
Code: Select all
procedure TForm2.Button1Click(Sender: TObject);
var
BlobStream: TStream;
begin
myquery1.Close;
MyQuery1.Open;
BlobStream := TMemoryStream.Create;
myquery1.GetBlob(myQuery1.FieldByName('IMAGEM')).SaveToStream(BlobStream);
Blobstream.Position := 0;
Image1.Picture.Bitmap.LoadFromStream(blobstream);
BlobStream.Free;
I'm using Delphi XE 10 Seattle
Re: INSERT AND READ IMAGE IN BLOB DATABASE
To load data from the Blob field to the VCL TImage component, use the following code:
Add the Jpeg mode to the Uses section to use this code.
Code: Select all
procedure TForm1.Button2Click(Sender: TObject);
var
BlobStream: TStream;
Jpg: TJPEGImage;
begin
BlobStream := TMemoryStream.Create;
myquery1.GetBlob(myQuery1.FieldByName('imagem')).SaveToStream(BlobStream);
Blobstream.Position := 0;
Jpg := TJPEGImage.Create;
try
Jpg.LoadFromStream(BlobStream);
Image2.Picture.Assign(Jpg);
finally
Jpg.Free;
end;
BlobStream.Free;
end;
Re: INSERT AND READ IMAGE IN BLOB DATABASE
Hello thank you so much! I can already save and retrieve photos . thank attention.
ps: the first code to retrieve photos that you wrote is for mobile?
ps: the first code to retrieve photos that you wrote is for mobile?
Re: INSERT AND READ IMAGE IN BLOB DATABASE
It is good to see that the problem has been solved. Feel free to contact us if you have any further questions about MyDAC.
Yes, you are right. The first code sample is designed for mobile development.
Yes, you are right. The first code sample is designed for mobile development.