?
Solved

Storing Images in Paradox

Posted on 1998-10-25
7
Medium Priority
?
202 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 300 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

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

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…
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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 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