/// <summary> /// Récupérer une image background /// </summary> /// <param name="url">Url de l'image</param> /// <returns>Image</returns> public static Image GetImageBackground(VO_BackgroundSerial serial) { //Pas d'image envoyée if (serial == null) { return(NotFoundPicture); } //Dictionnaire d'image if (_ImagesBackgrounds == null) { _ImagesBackgrounds = new Dictionary <string, Image>(); } //Création et ajout de l'image si non présente dans le dictionnaire string serialS = serial.ToString(); if (!_ImagesBackgrounds.ContainsKey(serialS)) { CreateNewImageBackground(serial); } //Renvoie de l'image try { return(_ImagesBackgrounds[serialS]); } catch (Exception e) { LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_KEY_NOT_FOUND, serial.ToString())); LogTools.WriteDebug(e.Message); return(NotFoundPicture); } }
/// <summary> /// Crée une nouvelle image background /// </summary> /// <param name="url">Url de l'image</param> public static void CreateNewImageBackground(VO_BackgroundSerial serial) { //Dictionnaire d'image if (_ImagesBackgrounds == null) { _ImagesBackgrounds = new Dictionary <string, Image>(); } //Ajout de l'image string serialS = serial.ToString(); if (!_ImagesBackgrounds.ContainsKey(serialS)) { try { Image mainBackground = null; if (serial.Padding == 0) { mainBackground = new Bitmap(serial.Size.Width, serial.Size.Height, EditorConstants.PERF_EDITOR_BITSPERPIXEL); Graphics graphic = Graphics.FromImage(mainBackground); graphic.FillRectangle(EditorHelper.Instance.TransparentBrushes[serial.BlockSize], new Rectangle(new Point(0, 0), serial.Size)); graphic.Dispose(); } else { int padding = serial.Padding * 2; mainBackground = new Bitmap(serial.Size.Width + padding, serial.Size.Height + padding, EditorConstants.PERF_EDITOR_BITSPERPIXEL); Graphics graphics = Graphics.FromImage(mainBackground); graphics.FillRectangle(new SolidBrush(Color.Gray), new Rectangle(new Point(0, 0), new Size(serial.Size.Width + padding, serial.Size.Height + padding))); Image temp = new Bitmap(serial.Size.Width, serial.Size.Height, EditorConstants.PERF_EDITOR_BITSPERPIXEL); Graphics graphicBackground = Graphics.FromImage(temp); graphicBackground.FillRectangle(EditorHelper.Instance.TransparentBrushes[serial.BlockSize], new Rectangle(new Point(0, 0), serial.Size)); graphics.DrawImage(temp, new Rectangle(new Point(serial.Padding, serial.Padding), serial.Size)); temp.Dispose(); graphicBackground.Dispose(); graphics.Dispose(); } _ImagesBackgrounds.Add(serialS, mainBackground); LogTools.WriteDebug(string.Format(Logs.MANAGER_IMAGE_CREATED, serial.ToString(), Logs.MANAGER_BACKGROUNDS)); } catch (InsufficientMemoryException ie) { LogTools.WriteInfo(Logs.MANAGER_MEMORY_ERROR); LogTools.WriteDebug(ie.Message); ResetResources(); CreateNewImageBackground(serial); } catch (Exception e) { LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, serial)); LogTools.WriteDebug(e.Message); _ImagesBackgrounds.Add(serialS, NotFoundPicture); } } }
/// <summary> /// Supprimer une image background /// </summary> /// <param name="url">Url de l'image</param> public static void DeleteImageBackground(VO_BackgroundSerial serial) { string serialS = serial.ToString(); if (_ImagesBackgrounds.ContainsKey(serialS)) { try { _ImagesBackgrounds[serialS].Dispose(); _ImagesBackgrounds.Remove(serialS); } catch (Exception e) { LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, serial.ToString())); LogTools.WriteDebug(e.Message); } } }
/// <summary> /// Rafraichi l'animation /// </summary> /// <param name="pContainer">Containeur de l'animation</param> /// <param name="pCurrentSprite">Sprite courant</param> /// <returns>Surface</returns> public Image RefreshAnimation(Rectangle container, Rectangle currentSprite) { //Chargement background if (_BackgroundAnimPreview == null) { _BackgroundAnimPreview = new VO_BackgroundSerial(new Size(container.Width, container.Height), EditorSettings.Instance.TransparentBlockSize); ImageManager.CreateNewImageBackground(_BackgroundAnimPreview); } //Preview Image sprite = new Bitmap(currentSprite.Width, currentSprite.Height); Graphics graphicsSprite = Graphics.FromImage(sprite); graphicsSprite.DrawImage(ImageManager.GetImageResource(_ResourceOriginal), new Rectangle(new Point(0, 0), new Size(currentSprite.Width, currentSprite.Height)), new Rectangle(new Point(currentSprite.X, currentSprite.Y), new Size(currentSprite.Width, currentSprite.Height)), GraphicsUnit.Pixel); Image mainSurface = FormsTools.GetImageReducedAndCentered(sprite, ImageManager.GetImageBackground(_BackgroundAnimPreview), container, new Rectangle(new Point(0, 0), new Size(currentSprite.Width, currentSprite.Height)), false); graphicsSprite.Dispose(); sprite.Dispose(); return(mainSurface); }
/// <summary> /// Rafraichi la ressource /// </summary> /// <param name="pContainer">Containeur de l'animation</param> /// <param name="pCurrentSprite">Sprite courant</param> /// <param name="pFull">False si la ressource est redimmensionnée, sinon true</param> /// <returns>Surface</returns> public Image RefreshRessource(Rectangle container, Rectangle currentSprite, bool full) { //Chargement background if (_BackgroundResource == null) { _BackgroundResource = new VO_BackgroundSerial(new Size(container.Width, container.Height), EditorSettings.Instance.TransparentBlockSize); ImageManager.CreateNewImageBackground(_BackgroundAnimPreview); } //Ressource Image resourceInSurfaceControl; Image resource = (Image)ImageManager.GetImageResource(_ResourceOriginal).Clone(); Graphics resourceGraphics = Graphics.FromImage(resource); Image highlighted = new Bitmap(currentSprite.Width, currentSprite.Height); Graphics highlightGraphics = Graphics.FromImage(highlighted); highlightGraphics.FillRectangle(EditorSettings.Instance.HighlightningBrush, new Rectangle(new Point(0, 0), new Size(highlighted.Width, highlighted.Height))); resourceGraphics.DrawImage(highlighted, new Rectangle(currentSprite.Location, new Size(resource.Width, resource.Height)), 0, 0, resource.Width, resource.Height, GraphicsUnit.Pixel, _ImageTransparency); if (!full) { resourceInSurfaceControl = FormsTools.GetImageReducedAndCentered(resource, ImageManager.GetImageBackground(_BackgroundResource), container, new Rectangle(new Point(0, 0), ImageManager.GetImageResource(_ResourceOriginal).Size), full); } else { resourceInSurfaceControl = FormsTools.GetImageReducedAndCentered(resource, ImageManager.GetImageBackground(_BackgroundResource), container, container, full); } resource.Dispose(); resourceGraphics.Dispose(); highlighted.Dispose(); highlightGraphics.Dispose(); return(resourceInSurfaceControl); }