Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Unable to view large Jpeg image from database using delphi

Posted on 2004-11-02
8
Medium Priority
?
1,100 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 59

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 59

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 59

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

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.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

618 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