2010-12-21 8 views
0

안녕하세요, 저는 온라인에서 찾은 XNA Gif 애니메이션 라이브러리를 사용하려고합니다. 실행 중이면 계속 예외가 표시됩니다. "전달 된 데이터의 크기가 너무 큽니다. 이 리소스에 비해 너무 작습니다. " GifAnimationContentTypeReaderXNA GIF 애니메이션 라이브러리 문제

이 광고에
 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); 
      } 
     } 

은 "프레임 [I] .SetData (j, RECT, 데이터 0 data.length입니다);" I donno하지만

누구나 이 들으

답변

0

가 (코드에서 : countdata.Length) 바이트의 수는 일이 괜찮나 방법을 알고 있지만, 데이터 길이는 정말 거대하다 width * height * bytesPerPixel, 어디 bytesPerPixel에 동일해야을 데이터 형식에 따라 다릅니다 (기본 값은 SurfaceFormat.Color이며 형식은 4입니다).

같지 않은 경우 해당 텍스처에 충분한 데이터가 없거나 데이터가 너무 많습니다.

을 (를) 왜 말할 수 있는지에 대한 질문에 충분한 정보가 제공되지 않아 값이 동일하지 않습니다.

+0

을, 그리고 난 비디오를 사용하는 것은 생각보다 쉽게 ​​할 더 많은 자원을 가지고 것을 발견했다. 어쨌든 Thxx –

0

코드에 버그가 있습니다. 이 코드 사용

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

} 그것은 나 같은 초보자를위한 매우 복잡

+1

버그 세부 사항에 약간의 정교화는 아무에게도 해를 끼치 지 않습니다. –