Задача библиотеки анимации XNA GIF - PullRequest
0 голосов
/ 21 декабря 2010

Эй, ребята, я пытаюсь использовать библиотеку анимации XNA Gif, которую я обнаружил в сети, затем, когда я бегу, она выдает мне исключение: «Размер передаваемых данных слишком большой или слишком маленький для этого ресурса «. для GifAnimationContentTypeReader

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

в этой строке "frames [i] .SetData (j, rect, data, 0, data.Length);" Я не знаю, как, но длина данных действительно огромна, хотя

Кто-нибудь знает, как это происходит ТНХ

Ответы [ 2 ]

0 голосов
/ 16 октября 2012

Ваш код содержит ошибку. Используйте этот код:

namespace GifAnimation
{
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.Graphics;
    using System;
    using Microsoft.Xna.Framework;

public sealed class GifAnimationContentTypeReader : ContentTypeReader<GifAnimation>
{
    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);

                // Convert RGBA to BGRA
                for (int a = 0; a < data.Length; a += 4)
                {
                    byte tmp = data[a];
                    data[a] = data[a + 2];
                    data[a + 2] = tmp;
                }

                frames[i].SetData(data);
            }
        }
        input.Close();
        return GifAnimation.FromTextures(frames);
    }
}

}

0 голосов
/ 21 декабря 2010

Количество байтов (в вашем коде: count и data.Length) должно быть равно width * height * bytesPerPixel, где bytesPerPixel зависит от формата данных (для формата по умолчанию SurfaceFormat.Color это 4) .

Если он не равен, у вас недостаточно данных (или слишком много данных) для этой текстуры.

Вы не предоставили достаточно подробностей в своем вопросе, чтобы я мог сказать вам , почему ваши значения не равны.

...