TmemoryStream Read/write [resolved] lazarus / 8-Other ---------------------------------------------------------------------- didiergm · 2009-07-22 19:37 Hello, Before loading a jpeg, I need to be able to read and do a few checks and changes on the fly then pass the result to  a timage.Picture; So I load a jpeg into a tmemorystream; do a series of readbuffer into an array [1..128] of bytes but when I come to do a Image.picture.loadfromstreamwithExt (m, '.jpg') I get an I/O error 103 file is not opened. and I fail to understand why it is doing this. If I do not touch the Memorystream (ie m.LoadfromFile then Image.picture.loadfromstreamwithExt (m, '.jpg')) for testing everything is right. So my question is can I read and write into a single tmemorystream ? could the I/O error 103 indicate that the JPG format is wrong ? (ie I've got a bug in my logic ?) thanks in advance Didier ---------------------------------------------------------------------- theo · 2009-07-22 20:27 A wild guess: m.position:=0; before passing to loadfromstreamwithExt ---------------------------------------------------------------------- didiergm · 2009-07-22 21:53 Theo, Done that, no change; but I am 99% there; I found a bug in my logic which was destroying the JPG structure. So I suspect the I/O error 103 is misleading and means in that case something like 'bad format' thanks for your help Didier ---------------------------------------------------------------------- theo · 2009-07-22 22:06 I don't know. I have no problems doing this: Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var   m: TMemoryStream;   a:array[1..128] of byte; begin  m:=TMemoryStream.create;  m.LoadFromFile('/home/theo/Documents/2009-01-01-185110.jpg');  m.Read(a,127);  m.Position:=0;  Image1.picture.LoadFromStreamWithFileExt(m, '.jpg');  m.free; end; ---------------------------------------------------------------------- didiergm · 2009-07-22 22:26 Theo, I confirm this was my (twisted ?) logic corrupting the jpg. I am writing an application that voluntarily corrupts a jpeg and restores it before display. Didier