Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

high memory usage when drawing an image to a bitmap

$
0
0
Hello,

I'm working on a radar for a game since some months, today I saw that the memory usage of my drawing function requires too much memory in my opinion, the last try it was over 200MB and still counting up without stopping.

In the function I load images from an imagelist to the image and let it draw, sometimes the function have to drawing more then 10 images, maybe is that the problem.

Here the code of the function what makes me worries:
        private static Bitmap DrawIcon(Bitmap img, string iconName, float X, float Y)
        {
            Graphics g_img = Graphics.FromImage(img);
            g_img.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            frmMain frmMain = new frmMain();
            Image Icon;
 
            try  
            {
                Icon = frmMain.imageList1.Images[iconName + ".png"];
                g_img.DrawImage(Icon, X, Y);
            }  
            catch (Exception ex)
            {
                Icon = null;
            }
            Icon.Dispose();
            g_img.Dispose();
            return img;
        }



The size of the icons in imagelist is 16x16 and are displayed in a Depth32Bit colordepth.

Viewing all articles
Browse latest Browse all 51036

Trending Articles