JPEG data stream in TImage

I have some image files stored in one file (some kind of archive). This file is as follows:

enter image description here

Well, it is divided into two segments - the header and the data segment. The title (green) contains various information, such as album name, location, date / time, description, number of photos in the album, etc. The data segment (blue and orange) has a simple structure and contains N x JPEG photos. I can extract this "imagedata" segment into a new TMemoryStream object, and now I want to show it using TImage.

I can use the SaveAsFile TMemoryStream method, set a temporary file name, load this file from TImage, and then delete the temporary file. This works, but I am wondering if there is a way to send this stream to TImage using temp. files.

Of course, I can write code to extract all these files to the hard drive, but the problem is that I have a lot of archives like this, and I just want to write an application to read these β€œalbums” instead of 20,000 photos on my hard disk.

In short, all I want is to do the following procedures (without using temporary files)

procedure ShowImageFromStream(data: TStream; img: TImage); begin ... end; 

Thanks in advance.

+8
delphi filestream delphi-7 timage
source share
1 answer

I'm not sure if this is what you are looking for, but this code should load the JPEG file from the stream into this TImage component:

 uses JPEG; procedure ShowImageFromStream(AImage: TImage; AData: TStream); var JPEGImage: TJPEGImage; begin AData.Position := 0; JPEGImage := TJPEGImage.Create; try JPEGImage.LoadFromStream(AData); AImage.Picture.Assign(JPEGImage); finally JPEGImage.Free; end; end; 
+18
source share

All Articles