Part 1: Insert Image to Blob Field Database,
Use Mysql 4.0.26 +zeoslib 6.15
----------
[syntax="delphi"]with dmdbConnPool.q2 do begin
SQL.clear;
SQL.Add('update employee set PHOTO=:iPic');
SQL.Add('where employeeid=:iEmp');
ParamByName('iEmp').AsString:=dbEmployeeID.text;
if Uppercase(ExtractFileExt(DBEdit14.Text))='.JPG' then begin
Picture:=TPicture.Create;
Picture.LoadFromFile(DBEDIT14.text);
Stream:=TMemoryStream.Create;
TJPEGImage(Picture.Graphic).SaveToStream(Stream);
ParamByName('iPic').SetBlobData(Stream.Memory,Stream.Size);
ExecSQL;
end
else if Uppercase(ExtractFileExt(DBEdit14.Text))='.BMP' then begin
JPG.Assign(Image1.Picture.Graphic);
JPG.CompressionQuality:=70;
JPG.SaveToStream(Stream);
ParamByName('iPic').SetBlobData(Stream.Memory,Stream.Size);
ExecSQL;
Showmessage('BITMAP are saved success : '+DBEdit14.Text);
end;
end;
end; // end of the If Course
Except
on E : Exception do begin
ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
ShowMessage('NOT SUCCESS TO UPLOAD IMAGE');
Exit;
end; // end of the Exception
end;
finally
JPG.Free;
Stream.Free;
end; // end of the finally try ( First Try )[/syntax]
==========
Part 2: query afterscroll method, to view image
[syntax="delphi"]with dmdbConnPool.q3 do begin
SQL.clear;
SQL.Add('select * from employee ');
SQL.Add('where Employeeid=:Employeeid');
ParamByName('Employeeid').AsString := EmpAdmin.dbEmployeeID.text;
ExecSQL;
open;
if not FieldByName('photo').IsNull then
try
MS:=TStringStream.Create('');
TBlobField(FieldByName('PHOTO')).SaveToStream(MS);
MS.Position:=0;
jpeg:=TJPEGImage.Create;
jpeg.LoadFromStream(MS);
EmpAdmin.Image1.Picture.Bitmap.Assign(jpeg);
finally
jpeg.Free;
ms.Free;
end // end of the try block
else begin
EmpAdmin.image1.Picture :=nil;
end // end of the begin
end[/syntax]
==========
If i use blobstream to save image to mysql, I don't know how to programming. If possible give me a hint, Why I save jpg while get
half of image, but bitmap now problem. I useing BLOB filed in my database. I think I part 1 have problem during save jpg, any change I can fix the jpg problem.
Thank you very much and.
[edit="Michael"]I put your code into syntax-tags - looks better now [/edit]
How to save jpg image
Moderators: gto, cipto_kh, EgonHugeist
Insert Image to Blob Field Database
Saludos iarthur.ora,
Por qué no intentas cambiar el tipo de campo de Blob a MediumBlob o LongBlob, sucede a veces que la imagen ocupa mucho espacio y solo estos últimos pueden almacenar.
Regards from Bolivia
Por qué no intentas cambiar el tipo de campo de Blob a MediumBlob o LongBlob, sucede a veces que la imagen ocupa mucho espacio y solo estos últimos pueden almacenar.
Regards from Bolivia
-
- Fresh Boarder
- Posts: 3
- Joined: 19.05.2009, 13:58
erro after post image
I use Delphi 2010 to save a JPG image into a field LONGBLOB, but after saving in a Mysql the Image is saved only BINARY. When I retrieve the image with "SELECT" error occurs "JPG ERROR # 53". Does anyone know why?
P.S. In Delphi 2006 it worked correctly.
Rodrigo Andrade de Oliveira
P.S. In Delphi 2006 it worked correctly.
Rodrigo Andrade de Oliveira
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
Have a look at the changes in SVN rev. 712 (http://fisheye2.atlassian.com/changelog/zeos/?cs=712)
This patch may solve your problems. It solved all the test suite's problems with delphi 2009+mysql.
Mark
This patch may solve your problems. It solved all the test suite's problems with delphi 2009+mysql.
Mark