Пример #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);
            }
        }
Пример #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;
            }
        }
Пример #3
0
        /*
         *      static string LogoSourceBluRay = mediaFolder + @"BLURAY.png";
         *      static string LogoSourceDVD = mediaFolder + @"DVD.png";
         *
         *      static string LogoCodecX264 = mediaFolder + @"AVC.png";
         *      static string LogoCodecXVid = mediaFolder + @"XVID.png";
         *      static string LogoCodecDivx = mediaFolder + @"DIVX.png";
         *      static string LogoCodecMpeg2 = mediaFolder + @"MP2V.png";
         *      static string LogoCodecAVC = mediaFolder + @"AVC.png";
         *
         *      static string LogoRes720 = mediaFolder + @"720p.png";
         *      static string LogoRes1080 = mediaFolder + @"1080p.png";
         *
         *      static string LogoDim16x9 = mediaFolder + @"WIDESCREEN.png";
         *      static string LogoDim4x3 = mediaFolder + @"FULLSCREEN.png";
         */
        public static string buildRating(double value, string offstar, string onstar, int width, int height)
        {
            try
            {
                Bitmap   b   = new Bitmap(width * 10, height);
                Image    img = b;
                Graphics g   = Graphics.FromImage(img);
                BaseConfig.MyAnimeLog.Write("Source: " + offstar + " Dest: " + onstar);
                Image  off     = ImageAllocator.LoadImageFastFromFile(GUIGraphicsContext.Skin + @"\Media\" + offstar);
                Image  on      = ImageAllocator.LoadImageFastFromFile(GUIGraphicsContext.Skin + @"\Media\" + onstar);
                int    val     = (int)Math.Floor(value);
                string tmpfile = onstar + "_" + ((int)val).ToString(CultureInfo.InvariantCulture) + "_";

                for (int x = 0; x < 10; x++)
                {
                    if (x < val)
                    {
                        g.DrawImage(on, new Rectangle(x * width, 0, width, height), new Rectangle(0, 0, on.Width, on.Height), GraphicsUnit.Pixel);
                    }
                    if (x >= val)
                    {
                        g.DrawImage(off, new Rectangle(x * width, 0, width, height), new Rectangle(0, 0, off.Width, off.Height), GraphicsUnit.Pixel);
                    }
                    if (x == val)
                    {
                        int sub = (int)((value - val) * width);
                        tmpfile += sub;
                        if (sub > 0)
                        {
                            var subSrc = (int)((value - val) * on.Width);
                            g.DrawImage(on, new Rectangle(x * width, 0, sub, height),
                                        new Rectangle(0, 0, subSrc, on.Height), GraphicsUnit.Pixel);
                        }
                    }
                }
                tmpfile += ".png";
                tmpfile  = Path.Combine(pathfortmpfile, @"\anime3_" + tmpfile + ".png");
                return(ImageAllocator.GetOtherImage(b, tmpfile, new Size(), true));
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write("The Rating Building Engine generated an error: " + ex.ToString());
                return(string.Empty);
            }
        }
Пример #4
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);
        }