示例#1
0
        protected override GifAnimation Read(ContentReader input, GifAnimation existingInstance)
        {
            int num = input.ReadInt32();

            Texture2D[]            frames  = new Texture2D[num];
            IGraphicsDeviceService service = (IGraphicsDeviceService)input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));

            if (service == null)
            {
                throw new ContentLoadException();
            }
            GraphicsDevice graphicsDevice = service.GraphicsDevice;

            if (graphicsDevice == null)
            {
                throw new ContentLoadException();
            }
            for (int i = 0; i < num; i++)
            {
                SurfaceFormat format       = (SurfaceFormat)input.ReadInt32();
                int           width        = input.ReadInt32();
                int           height       = input.ReadInt32();
                int           numberLevels = input.ReadInt32();
                frames[i] = new Texture2D(graphicsDevice, width, height, false, format);
                for (int j = 0; j < numberLevels; j++)
                {
                    int       count = input.ReadInt32();
                    byte[]    data  = input.ReadBytes(count);
                    Rectangle?rect  = null;
                    frames[i].SetData <byte>(j, rect, data, 0, data.Length);
                }
            }
            input.Close();
            return(GifAnimation.FromTextures(frames));
        }
        protected override GifAnimation Read(ContentReader input, GifAnimation existingInstance)
        {
            int num = input.ReadInt32();

            Texture2D[]            frames  = new Texture2D[num];
            IGraphicsDeviceService service = (IGraphicsDeviceService)input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));

            if (service == null)
            {
                throw new ContentLoadException();
            }
            GraphicsDevice graphicsDevice = service.GraphicsDevice;

            if (graphicsDevice == null)
            {
                throw new ContentLoadException();
            }
            for (int i = 0; i < num; i++)
            {
                SurfaceFormat format       = (SurfaceFormat)input.ReadInt32();
                int           width        = input.ReadInt32();
                int           height       = input.ReadInt32();
                int           numberLevels = input.ReadInt32();
                frames[i] = new Texture2D(graphicsDevice, width, height);
                for (int j = 0; j < numberLevels; j++)
                {
                    int    count    = input.ReadInt32();
                    byte[] data     = input.ReadBytes(count);
                    byte[] tempByte = new byte[data.Length];
                    for (int a = 0; a < data.Length; a += 4)
                    {
                        tempByte[a]     = data[a + 2];
                        tempByte[a + 1] = data[a + 1];
                        tempByte[a + 2] = data[a];
                        tempByte[a + 3] = data[a + 3];
                    }

                    frames[i].SetData(tempByte);
                }
            }
            input.Close();
            return(GifAnimation.FromTextures(frames));
        }
        protected override XTextureSequence Read(ContentReader input, XTextureSequence existingInstance)
        {
            int l = input.ReadInt32();

            Texture2D[] textures = new Texture2D[l];

            IGraphicsDeviceService service = (IGraphicsDeviceService)input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));

            if (service == null)
            {
                throw new ContentLoadException();
            }
            GraphicsDevice graphicsDevice = service.GraphicsDevice;

            if (graphicsDevice == null)
            {
                throw new ContentLoadException();
            }

            for (int i = 0; i < l; i++)
            {
                SurfaceFormat format       = (SurfaceFormat)input.ReadInt32();
                int           width        = input.ReadInt32();
                int           height       = input.ReadInt32();
                int           numberLevels = input.ReadInt32();
                textures[i] = new Texture2D(graphicsDevice, width, height, numberLevels, TextureUsage.None, format);

                for (int j = 0; j < numberLevels; j++)
                {
                    int       count = input.ReadInt32();
                    byte[]    data  = input.ReadBytes(count);
                    Rectangle?rect  = null;
                    textures[i].SetData <byte>(j, rect, data, 0, data.Length, SetDataOptions.None);
                }
            }
            input.Close();

            return(new XTextureSequence(textures));
        }