TraktPlugin.GUI.GUIImageHandler.DrawOverlayOnEpisodeThumb C# (CSharp) Méthode

DrawOverlayOnEpisodeThumb() public static méthode

Draws a trakt overlay, library/seen/watchlist icon on a episode thumb This is done in memory and wont touch the existing file
public static DrawOverlayOnEpisodeThumb ( string origThumb, MainOverlayImage mainType, RatingOverlayImage ratingType, Size size ) : Bitmap
origThumb string Filename of the untouched episode thumb
mainType MainOverlayImage
ratingType RatingOverlayImage
size System.Drawing.Size Size of returned image
Résultat System.Drawing.Bitmap
        public static Bitmap DrawOverlayOnEpisodeThumb(string origThumb, MainOverlayImage mainType, RatingOverlayImage ratingType, Size size)
        {
            Image image = GUIImageHandler.LoadImage(origThumb);
            if (image == null) return null;

            Bitmap thumb = new Bitmap(image, size);
            Graphics gph = Graphics.FromImage(thumb);

            string mainOverlayImage = TraktHelper.GetThemedSkinFile(SkinThemeType.Image, string.Format("trakt{0}.png", mainType.ToString().Replace(", ", string.Empty)));
            if (mainType != MainOverlayImage.None && File.Exists(mainOverlayImage))
            {
                Bitmap newThumb = new Bitmap(GUIImageHandler.LoadImage(mainOverlayImage));
                gph.DrawImage(newThumb, TraktSkinSettings.EpisodeThumbMainOverlayPosX, TraktSkinSettings.EpisodeThumbMainOverlayPosY);
            }

            string ratingOverlayImage = TraktHelper.GetThemedSkinFile(SkinThemeType.Image, string.Format("trakt{0}.png", Enum.GetName(typeof(RatingOverlayImage), ratingType)));
            if (ratingType != RatingOverlayImage.None && File.Exists(ratingOverlayImage))
            {
                Bitmap newThumb = new Bitmap(GUIImageHandler.LoadImage(ratingOverlayImage));
                gph.DrawImage(newThumb, TraktSkinSettings.EpisodeThumbRatingOverlayPosX, TraktSkinSettings.EpisodeThumbRatingOverlayPosY);
            }

            gph.Dispose();
            return thumb;
        }

Usage Example

Exemple #1
0
        /// <summary>
        /// Loads an Image from memory into a facade item
        /// </summary>
        /// <param name="imageFilePath">Filename of image</param>
        protected void SetImageToGui(string imageFilePath)
        {
            if (string.IsNullOrEmpty(imageFilePath))
            {
                return;
            }

            if (Show == null || Episode == null)
            {
                return;
            }

            // determine the overlay to add to poster
            MainOverlayImage mainOverlay = MainOverlayImage.None;

            // don't show watchlist overlay in personal watchlist window
            if (WindowID == (int)TraktGUIWindows.WatchedListEpisodes)
            {
                if ((GUIWatchListEpisodes.CurrentUser != TraktSettings.Username) && Episode.IsWatchlisted())
                {
                    mainOverlay = MainOverlayImage.Watchlist;
                }
                else if (Episode.IsWatched(Show))
                {
                    mainOverlay = MainOverlayImage.Seenit;
                }
            }
            else
            {
                if (Episode.IsWatchlisted())
                {
                    mainOverlay = MainOverlayImage.Watchlist;
                }
                else if (Episode.IsWatched(Show))
                {
                    mainOverlay = MainOverlayImage.Seenit;
                }
            }

            // add additional overlay if applicable
            if (Episode.IsCollected(Show))
            {
                mainOverlay |= MainOverlayImage.Library;
            }

            RatingOverlayImage ratingOverlay = GUIImageHandler.GetRatingOverlay(Episode.UserRating(Show));

            // get a reference to a MediaPortal Texture Identifier
            string suffix  = mainOverlay.ToString().Replace(", ", string.Empty) + Enum.GetName(typeof(RatingOverlayImage), ratingOverlay);
            string texture = GUIImageHandler.GetTextureIdentFromFile(imageFilePath, suffix);

            // build memory image, resize thumbnail in case its a fanart
            Image memoryImage = null;

            if (mainOverlay != MainOverlayImage.None || ratingOverlay != RatingOverlayImage.None)
            {
                memoryImage = GUIImageHandler.DrawOverlayOnEpisodeThumb(imageFilePath, mainOverlay, ratingOverlay, new Size(400, 225));
                if (memoryImage == null)
                {
                    return;
                }

                // load texture into facade item
                if (GUITextureManager.LoadFromMemory(memoryImage, texture, 0, 0, 0) > 0)
                {
                    ThumbnailImage = texture;
                    IconImage      = texture;
                    IconImageBig   = texture;
                }
            }
            else
            {
                ThumbnailImage = imageFilePath;
                IconImage      = imageFilePath;
                IconImageBig   = imageFilePath;
            }

            // if selected and is current window force an update of thumbnail
            this.UpdateItemIfSelected(WindowID, ItemId);
        }