Solved

Storing Images in Paradox

Posted on 1998-10-25
7
199 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In this tutorial viewers will learn how to create blended and gradiated shapes in Illustrator using the blend tool Draw two shapes, one of them in a different color: Select both and create a blend by going to Object > Blend > Make: Blends can also b…
In this Micro Tutorial viewers will learn the basic shortcuts and functions in InDesign.

705 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