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

DrawOverlayOnAvatar() public static méthode

Draws a trakt overlay, rating icon on a poster This is done in memory and wont touch the existing file
public static DrawOverlayOnAvatar ( string origAvartar, RatingOverlayImage ratingType, Size size ) : Bitmap
origAvartar string
ratingType RatingOverlayImage
size System.Drawing.Size Size of returned image
Résultat System.Drawing.Bitmap
        public static Bitmap DrawOverlayOnAvatar(string origAvartar, RatingOverlayImage ratingType, Size size)
        {
            Image image = GUIImageHandler.LoadImage(origAvartar);
            if (image == null) return null;

            Bitmap avatar = size.IsEmpty ? new Bitmap(image) : new Bitmap(image, size);
            Graphics gph = Graphics.FromImage(avatar);

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

            gph.Dispose();
            return avatar;
        }

Usage Example

        /// <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;
            }

            // check if this user item is a shout
            // we may need to apply a rating overlay to the avatar
            if (TVTag is TraktComment)
            {
                var shout = TVTag as TraktComment;

                // add a rating overlay if user has rated item
                var ratingOverlay = GUIImageHandler.GetRatingOverlay(shout.UserRating);

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

                // build memory image, resize avatar as they come in different sizes sometimes
                Image memoryImage = null;
                if (ratingOverlay != RatingOverlayImage.None)
                {
                    memoryImage = GUIImageHandler.DrawOverlayOnAvatar(imageFilePath, ratingOverlay, new Size(140, 140));
                    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;
                }
            }
            else
            {
                ThumbnailImage = imageFilePath;
                IconImage      = imageFilePath;
                IconImageBig   = imageFilePath;
            }

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