我最近将我的应用程序迁移到具有空安全性的 Flutter 2,但遇到了奇怪的错误。我有以下函数,用于将CameraImage (YUV) 转换为 RGB 图像,该函数在从 Flutter 1.26 到 2.3 并迁移之前完美运行。之后,它开始抱怨RangeError (index): Index out of range,我不明白,错误描述没有帮助。
static imageLib.Image convertYUV420ToImage(CameraImage cameraImage) {
final int width = cameraImage.width;
final int height = cameraImage.height;
final int uvRowStride = cameraImage.planes[1].bytesPerRow;
final int? uvPixelStride = cameraImage.planes[1].bytesPerPixel;
final image = imageLib.Image(width, height);
for (int w = 0; w < width; w++) {
for (int h = 0; h < height; h++) {
final int uvIndex =
uvPixelStride! * (w / 2).floor() + …
Run Code Online (Sandbox Code Playgroud)