locked
Image.FromFile(string Path) Memory Errors RRS feed

  • Question

  • User-1017819836 posted

    1) I am using a com component which holds a series of images in a locked database. The only way to access these images is first save them to a file and then use the Image.FromFile(path) and then I can use them in a .NET control.  The problem is that there is approximately 5000 plus images in one DB and 20,000 images in another DB.

    If I do this [Pseudo Code]

    List<Image> images = new List<Image>();

    Foreach(ComImage ci in ComDLL.Images)
    {

       string tmpPath = "c:\\tempfolder\\" + Guide.NewGuid().ToString;
       ci.SaveToFile(tmpPath);
      Image img = Image.FromFile(tmpPath);
     images.add(img);

    }

    The code runs slow because it has to write the image file to the harddrive then read the file into an image format.

     Is there any way I can create a virtual file which resides in memory and can be written to and read from much faster. For example, if I can use stream objects, then i can write the image data onto a stream and then use the Image.FromStream(streamname). This would speed up the whole process. 

    Any ideas?

    Sunday, September 7, 2008 12:02 AM

All replies

  • User1412644250 posted
    Obviously, it depends on the component you're using. Does it provide any other method to access the image? If there's just SaveToFile, I doubt there will be a nice way to do so.
    Sunday, September 7, 2008 1:30 AM
  • User-1017819836 posted

     Unfortunately there are no other methods available..  At the moment, I am working around this by creating ad hoc threads to run concurrently in order to speed the process up. This has helped on multi-core systems but it is still running relatively slow.

    Monday, September 8, 2008 1:24 PM