Unable to view large Jpeg image from database using delphi

Hi Experts!

Greetings!

I like to ask help from you guys about the codes im working on, its objective is to save and retrieve jpeg pictures in and out of an MSSQL database. I am able to do it with the class TJpegImage but I notice that when i save a picture with a size largen than 30kb or so, it cannot retrieve or display the image in full.

Below is the code I used to save, retrive and display it.

I appreciate any help you can give me.

Thanks you very much,
marlon_ric


*********** codes ***********
SAVING AN IMAGE
  with q1 do begin
    if qryphoto.eof then begin
      close; sql.Clear;
      sql.add('insert into clientphoto values (:clientno,:photo)');
      parambyname('clientno').AsString:= Q2clientno.Value;
      parambyname('photo').LoadFromFile(dlg.filename,ftGraphic       );
      execsql;
    end else begin
      close; sql.Clear;
      sql.add('update clientphoto set photo=:photo where clientno=:clientno');
      parambyname('clientno').AsString:= Q2clientno.Value;
      parambyname('photo').LoadFromFile(dlg.filename,ftGraphic       );
      execsql;
    end;
  end;

DISPLAYING AN IMAGE
  if not(qryphoto.eof) then begin
    jpg.LoadFromStream(qryphoto.CreateBlobStream(qryphotophoto,bmread));
    image1.Picture.Graphic:= jpg;
  end else image1.Picture.Graphic:= nil;










marlon_ricAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Is there any particular reason you have to stored the images in the database?

It is fairly common practice and arguably a better solution to store the images on disk and the path to the image in the database.

Just a thought ...
0
marlon_ricAuthor Commented:
Hi julian,

it is because one of our application needs to store a picture of our clients or members for proper identification

**cheers**
marlon
0
Julian HansenCommented:
Hi Marlon,

I understand - the point I was trying to make was this - instead of storing the image in the database you store it on a filesystem and just store the path i.e.

create table sometable
(
   name varchar(100),
   surname varchar(100),
   ...
   imagepath varchar(260)
)

insert into sometable (name, surname, ..., imagepath) values ('John','Smith',...,'C:\Pictures\JohnSmith.jpg')

In your code you simply load the image directly from the imagepath value in the database rather than have to mess around with blobs etc.

Julian
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

marlon_ricAuthor Commented:
Thanks! that is a great idea, there is only one difficulty I picture out with that strategy, since our setup is a client-server environment that span over a WAN and various servers are installed in different location to which systems can logon, I cannot decide to store the path of the image file into the database. This is because the LAN administrator may change the DNS or IP Address of the server for some reasons, if this happen not only the client station would be remapped to the server but also the path of each image file.

marlon
0
Julian HansenCommented:
That can be solved in a number of ways. One way would be to store the path seperately from the image name so you only store the name of the image file or alternatively the relative path of the image path i.e.

if the image store is

\\server\directory1\

you might want to break the images up by a category

\\server\directory1\category1\image1.jpg
\\server\directory1\category1\image2.jpg
\\server\directory1\category2\image3.jpg
\\server\directory1\category2\image4.jpg

You can then store the sub path for the image in the database as

\category1\image1.jpg
\category1\image2.jpg
\category2\image3.jpg
\category2\image4.jpg

And then you store the root path (\\server\directory1) in a configuration table or somewhere convenient for your application

If sub directories are not needed then you just store the image name.

This way you can change the server name in one place and your application will still work.



0
JpmSoftCommented:
You can even add a "LOCATIONS" table in which you store base url's information... something like this:

TABLE : LOCATIONS
=======================================
ID          Name                    URL
=======================================
1           Location 1              \\Computer\Share
2           Location 2              http://Server1/ImageGen.asp
3           Location 3              D:\Images


etc. etc etc


Then tou add a "LOCATION_ID" field to your image's table and start doing relations between data.-

I've been working on some projects where we had to scan/process/upload at least 2,000,000 images last year... in the first one we stored images on database and I can tell you that this was the worst experience we've ever had.-
So, JulianH is completely Right, start by AVOID any approach that means storing images in the database.-


Good Luck!

0
JpmSoftCommented:
Hmmm I forgot to say that the additional table will help you to make changes on one only place wich makes management easier...
0
marlon_ricAuthor Commented:
Thanks Julian!

this is one strategy that never crossed my mind, It will surely add up to some work around that i may consider next time I encounter the same situation.

thanks to you too JpmSoft for giving your thoughts on this problem.....

**** cheers! ****

marlon
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.