相关文章推荐
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have some image-files stored into one file (some kind of archive). That file looks like this:

Well, it's separated into two segments - header and data-segment. Header (green) contains various info, such as album name, location, date/time, description, number of photos in the album, etc. Data segment (blue & orange) has simple structure and it contains N x JPEG photo. I can extract that "imagedata" segment into new TMemoryStream object and now I want to show it using TImage.

I can use SaveAsFile method of TMemoryStream, set some temporary file-name, load that file from TImage, and later, remove temporary file. That works, but I'm wondering is there any way to send that stream into TImage w/out using temp. files.

Of course, I can write code to extract all those files on hard disk but problem is that I have a lot of archives like this one and just want to write application to read those "albums" instead of having 20,000+ photos on my hard drive.

In short, all I want is to make following procedure works (w/out using temp. files)

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

Thanks in advance.

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

JPEG; procedure ShowImageFromStream(AImage: TImage; AData: TStream); JPEGImage: TJPEGImage; begin AData.Position := 0; JPEGImage := TJPEGImage.Create; JPEGImage.LoadFromStream(AData); AImage.Picture.Assign(JPEGImage); finally JPEGImage.Free; +1 slightly diff var names but just the same as I was typing in, I need to learn to type quicker. – Dampsquid Apr 17, 2012 at 22:54 MY GOD, even I used TJPEGImage before, I totally missed LoadFromStream method!? Thanks a lot, that's it. – Wh1T3h4Ck5 Apr 17, 2012 at 23:06 When tried it but I load the date from memory stream and I get this error: JPEG error #53 – bob_saginowski Aug 21, 2014 at 13:45 @mitko.berbatov, there is a post about this error. Either the file is corrupted or the library cannot decompress it. – TLama Aug 21, 2014 at 13:59

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

 
推荐文章