Solved

Storing Images in Paradox

Posted on 1998-10-25
7
191 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…

708 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

11 Experts available now in Live!

Get 1:1 Help Now