Unable to view large Jpeg image from database using delphi

Posted on 2004-11-02
Last Modified: 2008-01-09
Hi Experts!


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,

*********** codes ***********
  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       );
    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       );

  if not(qryphoto.eof) then begin
    image1.Picture.Graphic:= jpg;
  end else image1.Picture.Graphic:= nil;

Question by:marlon_ric
    LVL 48

    Expert Comment

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

    Author Comment

    Hi julian,

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

    LVL 48

    Accepted Solution

    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.


    Author Comment

    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.

    LVL 48

    Expert Comment

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


    you might want to break the images up by a category


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


    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.

    LVL 4

    Expert Comment

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

    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!

    LVL 4

    Expert Comment

    Hmmm I forgot to say that the additional table will help you to make changes on one only place wich makes management easier...

    Author Comment

    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! ****


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    Title # Comments Views Activity
    seriesUp challenge 7 54
    Reading variable length EBCDIC in SAS 9 44
    scoresClump  challenge 31 70
    for loop with Set 4 25
    This is about my first experience with programming Arduino.
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    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…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    856 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

    9 Experts available now in Live!

    Get 1:1 Help Now