Page 1 of 1

How to save jpg image

Posted: 27.09.2005, 08:10
by iarthur.ora
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 :wink:[/edit]

Posted: 29.09.2005, 12:29
by fduenas
Plz try to use 6.5.1 version, there are now daily updates. 6.1.5 is not being updated since along time ago. I think this bug is already corrected.

Insert Image to Blob Field Database

Posted: 21.10.2005, 21:21
by username
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

erro after post image

Posted: 08.10.2009, 13:49
by dungabruxo
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

Posted: 09.10.2009, 21:16
by mdaems
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