Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解析报错 RangeError (index): Index out of range: index should be less than 157728: 157728 #678

Open
shiyu1991 opened this issue Sep 4, 2024 · 1 comment

Comments

@shiyu1991
Copy link

getGifFrameCount() async {
try{
ByteData data = await getData(); // 从资产中读取文件
Uint8List bytes = data.buffer.asUint8List(); // 转换为 Uint8List
// 检查数据大小是否合理
if (bytes.length < 100) {
debugPrint('gif解析错误 data is too small, may be corrupted.');
return;
}
debugPrint('gif解析bytes ${bytes.length}');

  final gif = img.decodeGif(bytes);
  if (gif != null) {
    gifMaxFrame = gif.numFrames.toDouble(); // 获取帧数
  }
  gifMinFrame = widget.gifMinFrame;
  if (gifMinFrame > gifMaxFrame) {
    gifMinFrame = gifMaxFrame;
  }
  setState(() {});
}catch(e,stacktrace){
  debugPrint('gif解析错误 $e');
  debugPrint("gif解析错误 stacktrace ${stacktrace.toString()}"); // 打印堆栈跟踪以获取更多调试信息
}

}
gif解析 bytes 397365
gif解析错误 RangeError (index): Index out of range: index should be less than 157728: 157728
gif解析错误 stacktrace #0 Uint8List.[]= (dart:typed_data-patch/typed_data_patch.dart:2280:7)

@shiyu1991
Copy link
Author

getGifFrameCount() async { try{ ByteData data = await getData(); // 从资产中读取文件 Uint8List bytes = data.buffer.asUint8List(); // 转换为 Uint8List // 检查数据大小是否合理 if (bytes.length < 100) { debugPrint('gif解析错误 data is too small, may be corrupted.'); return; } debugPrint('gif解析bytes ${bytes.length}');

  final gif = img.decodeGif(bytes);
  if (gif != null) {
    gifMaxFrame = gif.numFrames.toDouble(); // 获取帧数
  }
  gifMinFrame = widget.gifMinFrame;
  if (gifMinFrame > gifMaxFrame) {
    gifMinFrame = gifMaxFrame;
  }
  setState(() {});
}catch(e,stacktrace){
  debugPrint('gif解析错误 $e');
  debugPrint("gif解析错误 stacktrace ${stacktrace.toString()}"); // 打印堆栈跟踪以获取更多调试信息
}

} gif解析 bytes 397365 gif解析错误 RangeError (index): Index out of range: index should be less than 157728: 157728 gif解析错误 stacktrace #0 Uint8List.[]= (dart:typed_data-patch/typed_data_patch.dart:2280:7)

Future getData() async {
if (isFromNet) {
return NetworkAssetBundle(Uri.parse(widget.imageUrl)).load("");
}
return rootBundle.load(widget.imageUrl); // 从资产中读取文件
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant