Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Tore Bleken
  Where is Tore Bleken?
 Stokke
 Norway
 Tore Bleken
 To: bennet eze
  Where is bennet eze?
 LAGOS
 Nigeria
 bennet eze
 Tags
Subject: RE: pictures in reports
Thread ID: 395764 Message ID: 395910 # Views: 34 # Ratings: 2
Version: Visual FoxPro 9 SP2 Category: Reports and Printers
Date: Tuesday, January 21, 2014 9:59:45 AM         
   


> >
> > I can see that you are happy with the concept so my aim isn't to hit you over the head constantly with the facts of storing the information into a table. It might be too late to reverse the database decisions but if you can it is often well worth it. You can obviously retrieve the image files from the table using any of the methods people have suggested to you. If you retrieve them then you may well save a lot of space and potentially gain speed of access by storing the images as individual files.
> >
> > Here is a simple example. I took a fairly small PNG file, 84.8KB (86856 Bytes) and saved it into the simplest table I could, one memo (binary) field and the two files required for the single PNG came to 85.7KB (87758 Bytes). Now admittedly that isn't a huge overhead (+1.04%) but an overhead is an overhead and there is nothing to say at this stage that in different circumstances the overhead isn't bigger. If the table gets very big then to open the table and retrieve one image would be hampered by the size of all the images in the table. By saving the image into the table then you may have to do extra work at runtime to translate the binary information into a file that other systems can understand so bit by bit it is clear there are certain disadvantages to saving the information.
> >
> > Sorry if it feels like I'm labouring the point, the above is for information purposes only.
>
> You are perfectly correct. I was already thinking of moving the images from memo fields back to files when you replied. It does not involve much work. With all the information you people have supplied, my job is now simpler.
>
> Thanks
>
> Bennet Eze

You can extract all the pictures this way:

Local lcId As String, ;
   lcImageFolder As String, ;
   lcImagefield As String, ;
   lcType As String
m.lcImagefield = [image] && Replace with correct field name
m.lcId = [pk] && Replace with unique field name, I assume that it's character type
m.lcImageFolder = [picture] && Replace with picture folder name
Scan
   m.lcType = filetype(Evaluate(m.lcId)
   If !Empty(m.lcType)
      Copy Memo (m.lcImagefield) To (Addbs(m.lcImageFolder) + Trim(Evaluate(m.lcId)) + [.] + m.lcType)
   Endif
Endscan

Function filetype
   Lparameters lcData
   Local laDummy[1], ;
      lcContents As String, ;
      lcReturn As String, ;
      lnHandle As Number
   If Pcount() = 0 Or Vartype(lcData) # [C]
      lcReturn = []
   Else
      If Len(Trim(lcData)) < 1000 And Adir(laDummy, lcData) > 0 && File
         lnHandle = Fopen(lcData)
         lcContents = Fread(lnHandle, 50)
         Fclose(lnHandle)
      Else && Memory variab√łe
         lcContents = lcData
      Endif
      Do Case
         Case Len(lcContents) < 4
            lcReturn = []
         Case Left(lcContents, 3) = Chr(0xFF) + Chr(0xD8) + Chr(0xFF)
            lcReturn = [JPG]
         Case Left(lcContents, 3) = [GIF]
            lcReturn = [GIF]
         Case Substr(lcContents, 42, 3) = [EMF]
            lcReturn = [EMF]
         Case Left(lcContents, 4) = Chr(0xd0) + Chr(0xcf) + Chr(0x11) + Chr(0xe0)
            lcReturn = [XLS]
         Case Left(lcContents, 4) = Chr(0xD7) + Chr(0xCD) + Chr(0xC6) + Chr(0x9A)
            lcReturn = [WMF]
         Case Left(lcContents, 4) = Chr(0x4D) + Chr(0x4D) + Chr(0x00) + Chr(0x2A)
            lcReturn = [TIF]
         Case Left(lcContents, 4) = Chr(0x89) + [PNG]
            lcReturn = [PNG]
         Case Left(lcContents, 5) = Chr(0xd0) + Chr(0xcf) + Chr(0x11) + Chr(0xe0) + Chr(0xA1)
            lcReturn = [DOC]
         Case Left(lcContents, 5) = [%PDF-]
            lcReturn = [PDF]
         Case Left(lcContents, 2) = [BM]
            lcReturn = [BMP]
         Case Left(lcContents, 3) = [CWS] And Asc(Substr(lcContents, 4, 1)) < 16
            lcReturn = [SWF]
         Case Left(lcContents, 3) = [FWS]  And Asc(Substr(lcContents, 4, 1)) < 16
            lcReturn = [SWF]
         Otherwise
            lcReturn = []
      Endcase
   Endif
Return lcReturn

There's a fine line between helping and adding to the confusion.

How to create sample data

ENTIRE THREAD

pictures in reports Posted by bennet eze @ 1/18/2014 4:45:09 PM
RE: pictures in reports Posted by Pete Sass @ 1/18/2014 6:02:41 PM
RE: pictures in reports Posted by bennet eze @ 1/18/2014 9:40:29 PM
RE: pictures in reports Posted by Pete Sass @ 1/18/2014 11:21:57 PM
RE: pictures in reports Posted by Jun Tangunan @ 1/19/2014 1:31:28 AM
RE: pictures in reports Posted by David Mustakim @ 1/19/2014 4:11:23 AM
RE: pictures in reports Posted by Paul Gibson @ 1/20/2014 10:50:11 AM
RE: pictures in reports Posted by bennet eze @ 1/20/2014 9:10:18 PM
RE: pictures in reports Posted by Tore Bleken @ 1/20/2014 9:52:36 PM
RE: pictures in reports Posted by Paul Gibson @ 1/20/2014 10:16:57 PM
RE: pictures in reports Posted by David Mustakim @ 1/20/2014 10:21:27 PM
RE: pictures in reports Posted by Paul Gibson @ 1/20/2014 10:27:16 PM
RE: pictures in reports Posted by David Mustakim @ 1/20/2014 10:36:56 PM
RE: pictures in reports Posted by Paul Gibson @ 1/20/2014 10:46:06 PM
RE: pictures in reports Posted by bennet eze @ 1/21/2014 12:58:56 AM
RE: pictures in reports Posted by Vilhelm-Ion Praisach @ 1/21/2014 6:21:14 AM
RE: pictures in reports Posted by David Mustakim @ 1/21/2014 8:25:06 AM
RE: pictures in reports Posted by Paul Gibson @ 1/20/2014 10:43:46 PM
RE: pictures in reports Posted by bennet eze @ 1/21/2014 7:56:17 AM
RE: pictures in reports Posted by Tore Bleken @ 1/21/2014 9:59:45 AM
RE: pictures in reports Posted by bennet eze @ 1/21/2014 3:11:14 PM
RE: pictures in reports Posted by Tore Bleken @ 1/21/2014 3:21:07 PM
RE: pictures in reports Posted by Vilhelm-Ion Praisach @ 1/20/2014 10:24:51 PM
RE: pictures in reports Posted by tom knauf @ 1/21/2014 5:04:36 PM