Solved

A lot of graphics in one file

Posted on 1998-09-08
5
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Add visuals to your Prezi to keep your audience engaged. Learn how to embed images, edit them, and more in this video micro tutorial. Select "Insert" from the top menu in your Prezi editor: Select "Image": A toolbar will pop in from the right …
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.

728 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