[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Unable to view large Jpeg image from database using delphi

Posted on 2004-11-02
8
Medium Priority
?
1,106 Views
Last Modified: 2008-01-09
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;










0
Comment
Question by:marlon_ric
  • 3
  • 3
  • 2
8 Comments
 
LVL 61

Expert Comment

by:Julian Hansen
ID: 12470753
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
 

Author Comment

by:marlon_ric
ID: 12480797
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
 
LVL 61

Accepted Solution

by:
Julian Hansen earned 1500 total points
ID: 12481111
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:marlon_ric
ID: 12502745
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
 
LVL 61

Expert Comment

by:Julian Hansen
ID: 12502903
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
 
LVL 4

Expert Comment

by:JpmSoft
ID: 12508794
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
 
LVL 4

Expert Comment

by:JpmSoft
ID: 12508809
Hmmm I forgot to say that the additional table will help you to make changes on one only place wich makes management easier...
0
 

Author Comment

by:marlon_ric
ID: 12529795
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Loops Section Overview

591 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