Solved

A lot of graphics in one file

Posted on 1998-09-08
5
204 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this Micro Tutorial viewers will learn the basic shortcuts and functions in InDesign.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now