Solved

Storing Images in Paradox

Posted on 1998-10-25
7
195 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

831 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