Jump to content

Recommended Posts

Posted

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.

Posted

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

Posted (edited)

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

Edited by Ric_
Posted (edited)

No problem, it's only about 6 lines of code to do the actual conversion:

 

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

Edited by LosOjos

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...