1

I have a folder with height quantity of geolocated file, I want to make a KML with the placemark. No problem for the XML(KML) document, but the image are big and i want create a thumb(1/10) and small image (1/4) in separated folder.
The image are 4000x3000 allround 5mb, for little quantity not have problem but when the folder containg more of 35 image (in debug) i have the problem. I have try with disposable object used with Using, GC.collect to only image elaboration, but nothing.

I have folder to elaborate with 1400 image or more...is possible make to work this application with it?

public static class MyClass_img
{
    public static void ResizeImage(Image image, int width, int height, string pathImage)
    {
        using (var destImage = new Bitmap(width, height))
        {
            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);

                    var destRect = new Rectangle(0, 0, width, height);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }

            destImage.Save(pathImage);
        }
        GC.Collect();
    }

    public static string imageReduce(Image img, string path, int percentValue, string extension, string folder)
    {
        var dirName = new DirectoryInfo(path).Parent.Name;
        string pathImg = folder + dirName + "_" + Path.GetFileNameWithoutExtension(path) + extension;
        AprItalia_img.ResizeImage(img, img.Width / percentValue, img.Height / percentValue, pathImg);
        return pathImg;
    }

}

enter image description here

Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
  • 3
    You're probably not disposing the image you pass into `imageReduce(Image img, ...)`. – CodeCaster Jun 24 '17 at 14:18
  • Don't do `GC.Collect()` unless really required since frequent cleanup increases processing pressure. – Siva Gopal Jun 24 '17 at 14:21
  • Also what is the RAM your system has? – Siva Gopal Jun 24 '17 at 14:34
  • i have 16gb, but i hav read this ... is possible have excepption beacose use all of 1.2gb, ok is possible update to 4gb, but why it have all in memory? i think is necessary only the XML file, the image are saved in the folder and the object are dispose https://stackoverflow.com/questions/14186256/net-out-of-memory-exception-used-1-3gb-but-have-16gb-installed – Antonio Feliziani Jun 24 '17 at 14:59
  • I have set build to 64bit ...use all memory, for the moment have elaborate allround 500 file ...use all the ram of the system, but i not undestand why use all the ram...i dispose the image object and the other is only xml file – Antonio Feliziani Jun 24 '17 at 15:20

1 Answers1

0

You do not have to call GC.Collect().

As per MSDN,

Always call Dispose before you release your last reference >to the Image. Otherwise, the resources it is using will not >be freed until the garbage collector calls the Image >object's Finalize method

So in your case,it seems to be going for finalize.Also are you also releasing the Image object by calling it's dispose?

Rohith
  • 5,527
  • 3
  • 27
  • 31