how to write picture to stream? lazarus / 39-Graphics ---------------------------------------------------------------------- Godfather · 2017-08-16 08:34 i need a little help. My picture is already saved in bytes in a file. I want to show it with the help of any sort of Stream( Stream, Memorystream ... ), this is how I save my picture to file.     AssignFile( SourceFile, PictFilename );  // Picture     Reset( SourceFIle );                              // Open picture      SizeOfPict := FileSize( SourceFile );          Write( MyFile, SizeOfPict SHR 24 );       // save the size of the picture to the file     Write( MyFile, SizeOfPict SHR 16 );     Write( MyFile, SizeOfPict SHR  8 );     Write( MyFile, SizeOfPict SHR  0 );     for cntr := 1 to SizeOfPict do begin      read( SourceFIle, TempByte );                  // read picture in bytes      write( MyFile, TempByte );                        // write picture in bytes to file     end; And now I would like some help with how to show the picture in TImage. Thank you for your help. ---------------------------------------------------------------------- howardpc · 2017-08-16 08:48 What is wrong with 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 Image1.Picture.LoadFromFile(PictFilename);that you avoid it? ---------------------------------------------------------------------- Thaddy · 2017-08-16 08:53 Quotethis is how I save my picture to file.     AssignFile( SourceFile, PictFilename );  // Picture     Reset( SourceFIle );                              // Open picture  Then use streams.... OMG.... 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 .... oh well, Handoko will do this...beginend. ---------------------------------------------------------------------- Godfather · 2017-08-16 09:12 Quote from: howardpc on August 16, 2017, 10:48:19 amWhat is wrong with 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 Image1.Picture.LoadFromFile(PictFilename);that you avoid it? PictFilename is a string, but my picture is saved in bytes in the file! The thing is that in the file is more data, not only the picture but a memo text and other stuff, and everything is saved in BYTES, so its harder to get out the picture from that much data and open it, so the loadfromfile doesnt work, I tried that. That was the first thing I tried. ---------------------------------------------------------------------- J-G · 2017-08-16 10:42 Quote from: Godfather on August 16, 2017, 11:12:18 amPictFilename is a string, but my picture is saved in bytes in the file! The thing is that in the file is more data, not only the picture but a memo text and other stuff WHY ?? ---------------------------------------------------------------------- howardpc · 2017-08-16 12:30 Quote from: Godfather on August 16, 2017, 11:12:18 amPictFilename is a string, but my picture is saved in bytes in the file! The thing is that in the file is more data, not only the picture but a memo text and other stuff, If you are not comfortable with using streams to save and load varied data types to and from files, it would be much easier for you to keep to standard file formats and have spearate files for the picture, memo.txt (Memo.Lines.LoadFromfile/SaveToFile) and other stuff (file of record routines?). Read three files, and save three files. It will save you a lot of grief compared with trying to save and subsequently read varying data types turned into a single stream of bytes representing composite data arbitrarily strung together in a single file. ---------------------------------------------------------------------- balazsszekely · 2017-08-16 13:00 What is TempByte? I assume TByte(array of Byte). Then you can do something like this: 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 var  TempByte: TBytes;  Bs: TBytesStream;begin  //...     // read TempByte from file      Bs := TBytesStream.Create(TempByte);  try    Bs.Position := 0;    Image1.Picture.LoadFromStream(Bs);  finally    Bs.Free;  end; ---------------------------------------------------------------------- Remy Lebeau · 2017-08-17 18:20 Quote from: Godfather on August 16, 2017, 11:12:18 amPictFilename is a string, but my picture is saved in bytes in the file! The thing is that in the file is more data, not only the picture but a memo text and other stuff, and everything is saved in BYTES, so its harder to get out the picture from that much data and open it, so the loadfromfile doesnt work, I tried that. That was the first thing I tried. TPicture has LoadFromStream() and LoadFromStreamWithFileExt() methods. Since your data file knows where the picture data is located and how many bytes belong to the picture, you can either: 1. extract just those bytes from the file to a TMemoryStream or TByteStream, and then load that stream into TImage. 2. use a wrapper TStream that reads from the original file, limiting its reading to just the offsets of the picture data, and then load that wrapper stream into TImage. ---------------------------------------------------------------------- Godfather · 2017-08-23 06:16 Thank you, GetMem!