+ Post New Thread
Results 1 to 4 of 4
MIS Systems Thread, How do I export images from within SQL fields? in Technical; I have a database table containing images and names. I need to extract the images and save them as JPEGs ...
  1. #1

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    Boston, MA
    Posts
    7,597
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    183

    How do I export images from within SQL fields?

    I have a database table containing images and names. I need to extract the images and save them as JPEGs saved with the children's names as the filenames. This is because somebody has misplaced a disc and needs these images for the yearbook.

    I can use Crystal Reports to get a pretty report displaying the name and images but that doesn't really help me.

    Help would be much appreciated.

  2. #2

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,665
    Thank Post
    1,484
    Thanked 1,263 Times in 857 Posts
    Rep Power
    803
    Any good with C#.net?

    I wrote a program to do this recently, but it was for SIMS, so it takes an XML file as input and outputs the photos to a specified folder.

    If you use C#.net I'll send you the source code so you can adapt it, if not then if you can get a file containing the photo data (long string of seemingly random characters) and the names, either in XML or CSV, I'll adapt it for you and send you the exe

  3. #3

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    Boston, MA
    Posts
    7,597
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    183
    I actually discovered that I could export the Crystal report to Word and from word the images can be saved. Since I have no intention of performing the 'save as' step for 160 records, I feel that this is an acceptable result

    If you could ping me the C#, that would be awesome... I could then wait for the the guy to have performed the task on 100-odd of the images and then give him a folder full of nicely named files
    Last edited by Ric_; 17th May 2010 at 10:45 AM.

  4. #4

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,665
    Thank Post
    1,484
    Thanked 1,263 Times in 857 Posts
    Rep Power
    803
    No problem, it's only about 6 lines of code to do the actual conversion:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Drawing;
    
    namespace SIMSImageGrabber
    {
        class Program
        {
            static void Main(string[] args)
            {
                string RawData ="";
                string strSource ="";
                string strDest ="";
    
                foreach(string arg in args)
                {
                    if(arg.StartsWith("/S:"))
                        strSource = arg.Substring(3, arg.Length - 3);
    
                    if (arg.StartsWith("/D:"))
                        strDest = arg.Substring(3, arg.Length - 3);
    
                }
    
                if(strDest=="" || strSource=="")
                {
                    Console.WriteLine();
                    Console.WriteLine(@"SIMS.net Image Grabber V1.0");
                    Console.WriteLine();
                    Console.WriteLine(@"Parameters:");
                    Console.WriteLine(@"/S:""DATA SOURCE""      Source file which raw image data should be read from");
                    Console.WriteLine(@"/D:""SAVE AS""          Name of the file the converted image should be saved to");
                    Console.WriteLine();
                    Console.WriteLine(@"The source file specified by the /S: parameter should be a plain text file");
                    Console.WriteLine(@"containing the string of text that makes up the raw data for the image");
                    Console.WriteLine(@"(this string of text is returned as the ""Photo"" field in a relevant");
                    Console.WriteLine(@"SIMS .net XML report). The system will convert this text in to a JPEG image,");
                    Console.WriteLine(@"and save that  image to the file specified by the /D: parameter.");
                    Environment.Exit(0);
                }
    
                TextReader inFile = new StreamReader(strSource);
                RawData = inFile.ReadToEnd();
                inFile.Close();
    
                byte[] todecode = Convert.FromBase64String(RawData);
                MemoryStream ms = new MemoryStream(todecode);
                Image img = Image.FromStream(ms);
    
                img.Save(strDest);
            }
        }
    }

    EDIT:
    Seems this is an old version that does one image at a time, shouldn't be too difficult to adapt it though, the only really important part is the conversion of the photo data string from base 64
    Last edited by LosOjos; 17th May 2010 at 10:48 AM.



SHARE:
+ Post New Thread

Similar Threads

  1. clean up old fields
    By itgeek in forum Scripts
    Replies: 1
    Last Post: 26th February 2010, 12:34 PM
  2. Script to populate AD fields
    By FN-GM in forum Scripts
    Replies: 21
    Last Post: 29th July 2009, 02:14 PM
  3. Formatting Data Fields
    By tw15ns in forum MIS Systems
    Replies: 1
    Last Post: 3rd January 2009, 04:38 PM
  4. [MS Office - 2003] Access - Calculated Fields
    By garethedmondson in forum Office Software
    Replies: 2
    Last Post: 11th December 2008, 04:22 PM
  5. Quick letter fields not substituted
    By cjohnsonuk in forum MIS Systems
    Replies: 4
    Last Post: 20th March 2008, 02:42 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •