Solved

A lot of graphics in one file

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 54
Mobile Keyboard covers the display of the TMemo 3 87
Delphi: ForceDirectory plain function 7 32
Firemonkey webbrowser scrollbars ? 1 41
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

777 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