Solved

Unable to view large Jpeg image from database using delphi

Posted on 2004-11-02
1,051 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
Question by:marlon_ric
    8 Comments
     
    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 ...
    0
     

    Author Comment

    by:marlon_ric
    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 48

    Accepted Solution

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

    Author Comment

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

    \\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
    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
    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
    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

    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