Paint.PictureIOManager.LoadData C# (CSharp) Méthode

LoadData() public méthode

Loads existing image data from disk into the undoRedoRenderTargets and copies latest canvas recorder files into the 'working folder'
public LoadData ( GraphicsDevice device, SpriteBatch spriteBatch, RenderTarget2D undoRedoRenderTargets, Color backgroundColor ) : void
device GraphicsDevice /// Graphics device required for rendering ///
spriteBatch Microsoft.Xna.Framework.Graphics.SpriteBatch /// Sprite Batch for rendering the images into the rendertargets ///
undoRedoRenderTargets Microsoft.Xna.Framework.Graphics.RenderTarget2D /// Sequence of images representing the undo/redo chain ///
backgroundColor Color /// background color for all rendering ///
Résultat void
        public void LoadData(
			GraphicsDevice device, 
			SpriteBatch spriteBatch, 
			RenderTarget2D[] undoRedoRenderTargets,
			Color backgroundColor)
        {
            var imageStateData = this.LoadImageStateData();

            int end = imageStateData.FirstSavePoint == 0 ? imageStateData.LastSavePoint : imageStateData.MaxUndoRedoCount - 1;

            // Don't read more than we need to - hence above we are calculating whether we have used all the renderTarets
            for (int count = 0; count <= end; count++)
            {
                // Load the render target image
                using (var imageTexture= Texture2D.FromFile(
                        device,
                        this.filenameResolver.ImageSavePointFilename(count)))
                {
                    device.SetRenderTarget(undoRedoRenderTargets[count]);
                    spriteBatch.Begin();
                    device.Clear(backgroundColor);
                    spriteBatch.Draw(imageTexture, Vector2.Zero, backgroundColor);
                    spriteBatch.End();
                }

                // copy the master canvas recorder file into the working folder.
                // We will then read/write to/from the working folder until the final save at the end,
                // thus avoiding problem where render targets and playback files are out of sync if the
                // app exists early
                File.Copy(
                    this.filenameResolver.MasterCanvasRecorderFilename(count),
                    this.filenameResolver.WorkingCanvasRecorderFilename(count),
                    true);
            }
        }