internal static string BuildImages(int width, int height, List <GUIOverlayImage> listOverlayImages, string inMemoryFileID)
        {
            if (GUITextureManager.GetCachedTexture(inMemoryFileID) != null)
            {
                return(inMemoryFileID);
            }

            List <Image>           imgs  = new List <Image>();
            List <GUIOverlayImage> ovrls = new List <GUIOverlayImage>();

            // step one: Resize all Images to fit in Width, Height
            for (int i = 0; i < listOverlayImages.Count; i++)
            {
                if (listOverlayImages[i].Width == 0 || listOverlayImages[i].Height == 0)
                {
                    continue;
                }

                Image single = null;
                try
                {
                    single = LoadImageFastFromFile(listOverlayImages[i].ThemedFileName);
                    if (single == null)
                    {
                        continue;
                    }
                    if (single.Width == 0 || single.Height == 0)
                    {
                        continue;
                    }
                }
                catch (Exception)
                {
                    Log.Debug("GUIImageAllocator: Skip. Could not load Image file... " + listOverlayImages[i].FileName);
                    continue;
                }

                if (listOverlayImages[i].Width != single.Width || listOverlayImages[i].Height != single.Height)
                {
                    single = MediaPortal.Util.Utils.ResizeImage(single, new Size(listOverlayImages[i].Width, listOverlayImages[i].Height), _preserveAspectRatio);
                }

                imgs.Add(single);
                ovrls.Add(listOverlayImages[i]);
            }
            if (imgs.Count == 0)
            {
                return(string.Empty);
            }

            // step two: finally draw all images
            Bitmap   bmp = new Bitmap(width, height);
            Image    img = bmp;
            Graphics g   = Graphics.FromImage(img);

            try
            {
                for (int i = 0; i < imgs.Count; i++)
                {
                    g.DrawImage(imgs[i], ovrls[i].posX, ovrls[i].posY);
                }
            }
            finally
            {
                g.Dispose();
            }

            // step three: build final image in memory
            try
            {
                // we don't have to try first, if name already exists mp will not do anything with the image
                GUITextureManager.LoadFromMemory(bmp, inMemoryFileID, 0, width, height);

                if (!string.IsNullOrEmpty(inMemoryFileID) && !_cachedAllocatorImages.Contains(inMemoryFileID))
                {
                    _cachedAllocatorImages.Add(inMemoryFileID);
                }
            }
            catch (Exception)
            {
                Log.Error("GUIImageAllocator: BuildImages: Unable to add to MP's Graphics memory: " + inMemoryFileID);
                return(string.Empty);
            }
            return(inMemoryFileID);
        }
 private static void Flush(string sTextureName)
 {
     Log.Debug("GUIImageAllocator: Flush {0}", sTextureName);
     GUITextureManager.ReleaseTexture(sTextureName);
 }