Sign in to follow this  

XNA Gif Library Help

Recommended Posts

I've been trying to get GIF support in my XNA projects and the only XNA GIF Library I could find was [url=""]this[/url] one.

First I tried the original code then I tried duplicating it (almost word for word), but I still get this error:

Argument Exception was unhandled
The size of the data passed in is too large or too small for this resource.

However, when I do the math myself, it should work fine.

My width is 550, height 400. That should be a size of 880000 as per the instructions I found [url=""]here[/url].

When I debug the locals they come out as such.

I'm not really sure what's going wrong.

The code with the error:

[code]namespace AnimatedSprite
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using Microsoft.Xna.Framework;

public sealed class AnimatedSpriteContentTypeReader : ContentTypeReader<AnimatedSprite>
protected override AnimatedSprite Read(ContentReader input, AnimatedSprite 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); // ERROR OCCURS ON THIS LINE
return AnimatedSprite.FromTextures(frames);


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this