Solved

A lot of graphics in one file

Posted on 1998-09-08
5
207 Views
Last Modified: 2013-11-19
Hi, people! Expert Exchange rulz! Delphi RULZ!!

well, i need some help from you.
I want to create a file (just one) with pictures (TJPEG) and later, read the file and view each graphic. Example:

var
  TamGraph: Word;
  Graphic: TFileStream;
  GFile: TFilestream;
begin
  If OpenPictureDialog1.Execute then
    begin
      Graphic := TFileStream.Create (OpenPictureDialog1.Filename);
      GFile := TFileStream.Create ('test.dat', fmCreate);
      TamGraph := Word (Graphic.Size);
      GFile.Write (TamGraph, SizeOf(TamGraph));
      GFile.CopyFrom (Graphic, TamGraf);
      etc etc etc
   end;
   
  Well, when I try to load one of these graphics (using Streams), I allways get a error message. Example:

var
  TamGraph: Word;
  TempGraph: TMemoryStream;
begin
  TempGraph := TMemoryStream.Create;
  GFile.Seek (0, soFromBeginning);
  GFile.Read (TamGraph, SizeOf(TamGraph));
  TempGraph.SetSize (TamGraph);
  TempGraph.CopyFrom (GFile, TamGraph);
  Image1.Picture.Graphic.LoadFromStream (TempGraph);
  {Here a error occurs. I tried too:}
  TJpegImage(Image1.Picture).LoadFromStream (TempGraph);
  {Another error}
 end;

  What can I do?
  Please note: The graphic is a Jpeg Image, a put JPEG on uses etc etc. Please, help me!!!

thanks, people!

  Joaquim
 
0
Comment
Question by:joaquim
5 Comments
 
LVL 7

Expert Comment

by:BlackMan
ID: 1339095
How about using the JPEG stream? In D3 you must install it yourself (check http://www.inprise.com/devsupport/delphi/ti_list/TI3333.html), in D4 it is included with the install..

0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1339096
Oops, it seems like you allready are using it, sorry.. Then, have you checked the example under HELP\Examples\JPEG ?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1339097
joaquim,

I don't work with JPEG (yet). But your sources look correct. So perhaps you should try to do the same with a simple bitmap instead of a JPEG, just to check whether the problem is in your file operations or in the JPEG operations...

Regards, Madshi.
0
 
LVL 4

Accepted Solution

by:
d003303 earned 100 total points
ID: 1339098
Hi joaquim,
I know your problem very well. The TPicture object in Delphi is great, you can add several graphic formats at runtime and you never have to know much about it. But with streams, oh my god !
TPicture gets the actual graphic class out of a format list, an implemented (so not accessable from out of the unit) variable. There are interfaced fucntions to register additional graphic formats, but no chance to query them.
TPicture instanciates the graphic class fromout the file extension, So the only way to get a format independent application is to go through a temporary file.

Image1.Picture.Graphic.LoadFromStream (TempGraph);

This line crashes when there is no bitmap/icon/metafile/whatever assigned to TImage.
If you know that the app only uses JPEGs, you can pre-create an instance of TJPEGImage, assign it to Image1.Picture, then it works. But that's the dirty way.

Another solution is to keep a duplicate of the extension/grapic-class list like the Graphics unit does. This is duplicate programming, but the only way to be flexible with graphic formats within streams.

Hope this helps,
Slash/d003303
0
 

Author Comment

by:joaquim
ID: 1339099
thank you all for the help!

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question