Solved

A lot of graphics in one file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SVG, D3, scaling, translation 11 141
Exdpanding a PNG image 15 73
Configuring Autocad with a Quadro K4000 graphics card 23 172
How to make dynamic image files 3 80
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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":…
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.

943 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

6 Experts available now in Live!

Get 1:1 Help Now