Blobs and TPicture lazarus / 16-Databases ---------------------------------------------------------------------- TRNelson · 2016-03-26 15:32 I have a small snippet of code that loads a picture file and stores it in a Blob in a table. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SQLQuery1.SQL.Text:= 'insert into Photos (PhotoID, FileName, Content) values (:PhotoID, :FileName, :Content)';SQLQuery1.ParamByName('PhotoId').AsInteger   := cntr;SQLQuery1.ParamByName('FileName').AsString   := Info.Name;SQLQuery1.ParamByName('Content').LoadFromFile(FName, ftBlob);SQLQuery1.ExecSQL;SQLTransaction1.Commit; It works well and does the job.  I would like to change the code so that the picture data comes from a TPicture object instead.  I could write the TPicture to a temporary file and reuse the code but that is pretty inefficient and I would rather extract the data directly from TPicture without having to resort to an intermediate file. I can't find an elegant way of doing this.  All suggestions are welcomed! ---------------------------------------------------------------------- Leledumbo · 2016-03-26 16:04 There's no direct way as far as I can find. You can use memory stream as intermediate storage, at least it won't suffer from disk I/O latency. ---------------------------------------------------------------------- TRNelson · 2016-03-26 16:47 Quote from: Leledumbo on March 26, 2016, 05:04:34 pmThere's no direct way as far as I can find. You can use memory stream as intermediate storage, at least it won't suffer from disk I/O latency. That's what I thought as well.  The picture is already loaded in a TPicture.  Time to do some research on memory streams. ---------------------------------------------------------------------- TRNelson · 2016-03-26 17:30 Well, that turned out to be a lot easier than I thought it would be.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Thumbnail.SaveToStream(MyStream);MyStream.Position := 0;Image1.Picture.LoadFromStream(MyStream); I am continually surprised on how feature rich this system is.  It is a far more sophisticated than what I used to use 40 years ago. Fortran and S/360 Assembly language on punch cards. ---------------------------------------------------------------------- Zath · 2016-04-11 19:42 Is position the actual physical position of an image file in a directory ? ---------------------------------------------------------------------- howardpc · 2016-04-11 21:21 No, Position is a stream property, a pointer to a location somewhere within the entire length of the stream (for streams where Length makes sense) where the next stream read/write will take place. To load a picture you want to begin at Position zero, right at the beginning of the stream (otherwise you would fail to read the initial bytes). ---------------------------------------------------------------------- Zath · 2016-04-12 00:07 Thank you howard.