Solved

Storing Images in Paradox

Posted on 1998-10-25
7
192 Views
Last Modified: 2013-11-19
I am using a DbImage to let the user select images via an OpenPictureDialog. The images are then stored in a paradox table. I understand that Paradox will not recognize jpeg's
as a valid field value but storing pictures as bmp's requires major disk space.
I want to be able to let the user store jpegs as well as bmps in the table for viewing as a photo album.
My question is: Is there any way to do this in a paradox table?? In fact, it would be nice to let the user convert all pics to jpeg's if they want to conserve disk space.
Is this possible?? Thanks
Jim

0
Comment
Question by:JStan
  • 4
  • 2
7 Comments
 

Expert Comment

by:elkiors
ID: 1344255
I don't know how to do it, but I know you need to use BLOB fields, they allow you to use ANY binary info in them

Darren
0
 
LVL 5

Accepted Solution

by:
ronit051397 earned 150 total points
ID: 1344256
I can give you an example with Metafiles because TImage can store metafiles, but you can conclude from this to jpegs.

To save a metafile to blob field:

procedure ....
var MetaStream : TMemoryStream;

begin
.
  MetaStream := TMemoryStream.Create;
  Image1.picture.Metafile.SavetoStream(MetaStream);
  (Table1.fieldbyname('Meta') as TBlobField).LoadFromStream(MetaStream);
  Table1.post;
  MetaStream.Free;
.
end;

To load from a metafile blob:
procedure .....
var MetaStream : TMemoryStream;
.
begin
.
  MetaStream := TMemoryStream.Create;
  (Table1.fieldbyname('Meta') as TBlobField).SaveToStream(MetaStream);
  {you must set the stream to position one so you have something to write!}
  IconStream.Position := 0;
  Image1.Picture.Metafile.LoadfromStream(MetaStream);
  MetaStream.Free;
end;

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1344257
JStan, Did it help you?
0
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.

 

Author Comment

by:JStan
ID: 1344258
Points up to 150.
I tried to use the code you posted but here is what I have.
It works great as long as I know what graphic type I have.
The following works to save to the table:

procedure TForm28.Image2DblClick(Sender: TObject);
var
MainStream : TMemoryStream;
begin
     if OpenPictureDialog1.Execute then
        begin
             DbNavigator3.BtnClick(nbEdit);
             Image2.Picture.LoadFromFile(OpenPictureDialog1.FileName);
             MainStream := TMemoryStream.Create;
             if Image2.Picture.Graphic is TMetaFile then
                Image2.picture.Metafile.SavetoStream(MainStream)
             else
             if Image2.Picture.Graphic is TBitMap then
                Image2.picture.BitMap.SavetoStream(MainStream)
             else
             if Image2.Picture.Graphic is TIcon then
                Image2.picture.Icon.SavetoStream(MainStream)
             else
             if Image2.Picture.Graphic is TJPegImage then
                TJpegImage(Image2.picture.Graphic).SavetoStream(MainStream);
             (DataModule2.Table4.fieldbyname('PhotoPic') as TBlobField).LoadFromStream(MainStream);
             MainStream.Free;
        end;
end;

or to simplify things, this will work also:

procedure TForm28.Image2DblClick(Sender: TObject);
var
MainStream : TMemoryStream;
begin
     if OpenPictureDialog1.Execute then
        begin
             DbNavigator3.BtnClick(nbEdit);
             Image2.Picture.LoadFromFile(OpenPictureDialog1.FileName);
             MainStream := TMemoryStream.Create;
             Image2.picture.Graphic.SavetoStream(MainStream);
             (DataModule2.Table4.fieldbyname('PhotoPic') as TBlobField).LoadFromStream(MainStream);
             MainStream.Free;
        end;
end;

Now here is the problem:
This will not work:

procedure TForm28.LoadPicture(Sender: TObject);
var
MainStream : TMemoryStream;
   begin
           MainStream := TMemoryStream.Create;
           if not(DataModule2.Table4.fieldbyname('PhotoPic') as TBlobField).IsNull then
           begin
           (DataModule2.Table4.fieldbyname('PhotoPic') as TBlobField).SaveToStream(MainStream);
           MainStream.Position := 0;
           Image2.Picture.Graphic.LoadFromStream(MainStream);
           end;
           MainStream.Free;
   end;

It doesn't work I think because 'Graphic' is undefined.
And if I write:

Image2.Picture.Metafile.LoadFromStream(MainStream);

it will work for a Metafile only.

Problem is that when streaming in the graphic, I need to know what graphic.

WHEW!!!!

Any more help is greatly appreciated.
Jim

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1344259
If you need to deal with JPeg, then take a look on the TJPEGImage help.
Also take a look at Borland's demo:
C:\Program Files\Borland\Delphi 3\HELP\EXAMPLES\JPEG\Jpegproj.dpr

Try this:
uses jpeg;
.
TJPEGImage(Image2.Picture.Graphic).LoadFromStream(MainStream);
TJPEGImage(Image2.Picture.Graphic).SavetoStream(MainStream);
0
 

Author Comment

by:JStan
ID: 1344260
Thats great if you know that the picture is a JPeg.
But is there any way to tell what the graphic is as it is streamed in.
Unless I know what type graphic it is, I can't display it in the TImage component.
The problem is NOT streaming in the graphic. The error occurs when I try to place
the graphic into the TImage.
Do you know what I mean?
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1344261
Your original question was about jpegs.
TPicture cannot support any kind of picture "just like that". If you look at the TPicture.Graphic Help file you see that you must define a new class for each new stucture, so that TPicture can "support" it:
"...Use Graphic to specifiy what graphic the TPicture object contains. The graphic can be a bitmap, icon, or metafile, or user-defined graphic class..."
TJPEGImage is a user-defined graphic class, already defined by Borland.
Ronit,


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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…

911 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

24 Experts available now in Live!

Get 1:1 Help Now