Esempio n. 1
0
        public static string buildLogoImage(List <string> logosForBuilding, int imgWidth, int imgHeight)
        {
            try
            {
                if (logosForBuilding.Count == 1)
                {
                    return(logosForBuilding[0]);
                }
                else if (logosForBuilding.Count > 1)
                {
                    tmpFile = string.Empty;
                    foreach (string logo in logosForBuilding)
                    {
                        tmpFile += System.IO.Path.GetFileNameWithoutExtension(logo);
                    }
                    tmpFile = Path.Combine(pathfortmpfile, @"\anime3_" + tmpFile + ".png");

                    Bitmap   b   = new Bitmap(imgWidth, imgHeight);
                    Image    img = b;
                    Graphics g   = Graphics.FromImage(img);
                    appendLogos(logosForBuilding, ref g, imgHeight, imgWidth);

                    return(ImageAllocator.GetOtherImage(b, tmpFile, new Size(), true));                    // don't resize in allocator
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write("The Logo Building Engine generated an error: " + ex.ToString());
                return(string.Empty);
            }
        }
Esempio n. 2
0
        static void appendLogos(List <string> logosForBuilding, ref Graphics g, int totalHeight, int totalWidth)
        {
            int          noImgs     = logosForBuilding.Count;
            List <Image> imgs       = new List <Image>();
            List <Size>  imgSizes   = new List <Size>();
            int          spacer     = 5;
            int          checkWidth = 0;
            // step one: get all sizes (not all logos are obviously square) and scale them to fit vertically
            Image single = null;
            float scale = 0, totalHeightf = (float)totalHeight;
            Size  tmp   = default(Size);
            int   x_pos = 0;

            for (int i = 0; i < logosForBuilding.Count; i++)
            {
                try
                {
                    single = ImageAllocator.LoadImageFastFromFile(logosForBuilding[i]);
                }
                catch (Exception)
                {
                    BaseConfig.MyAnimeLog.Write("Could not load Image file... " + logosForBuilding[i]);
                    return;
                }
                scale       = totalHeightf / (float)single.Size.Height;
                tmp         = new Size((int)(single.Width * scale), (int)(single.Height * scale));
                checkWidth += tmp.Width;
                imgSizes.Add(tmp);
                imgs.Add(single);
            }
            // step two: check if we are too big horizontally and if so scale again
            checkWidth += imgSizes.Count * spacer;
            if (checkWidth > totalWidth)
            {
                scale = (float)checkWidth / (float)totalWidth;
                for (int i = 0; i < imgSizes.Count; i++)
                {
                    imgSizes[i] = new Size((int)(imgSizes[i].Width / scale), (int)(imgSizes[i].Height / scale));
                }
            }
            // step three: finally draw them
            for (int i = 0; i < imgs.Count; i++)
            {
                g.DrawImage(imgs[i], x_pos, totalHeight - imgSizes[i].Height, imgSizes[i].Width, imgSizes[i].Height);
                x_pos += imgSizes[i].Width + spacer;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Takes an Image and tries to load it into MP' graphics memory
        /// If the sFileName was already in memory, it will not be reloaded (basically it caches)
        /// </summary>
        /// <param name="image">The System.Drawing.Bitmap to be loaded</param>
        /// <param name="identifier">A unique identifier for the image so it can be retrieved later on</param>
        /// <returns>memory identifier</returns>
        public static string buildMemoryImage(Image image, string identifier, System.Drawing.Size size, bool buildIdentifier)
        {
            string name = buildIdentifier ? ImageAllocator.buildIdentifier(identifier) : identifier;

            try
            {
                // we don't have to try first, if name already exists mp will not do anything with the image
                if (size.Height > 0 && (size.Height != image.Size.Height || size.Width != image.Size.Width)) //resize
                {
                    image = Resize(image, size);
                }
                //PerfWatcher.GetNamedWatch("add to TextureManager").Start();
                GUITextureManager.LoadFromMemory(image, name, 0, size.Width, size.Height);
                //PerfWatcher.GetNamedWatch("add to TextureManager").Stop();
            }
            catch (Exception)
            {
                //MPTVSeriesLog.Write("Unable to add to MP's Graphics memory: " + identifier);
                return(string.Empty);
            }
            return(name);
        }