title: How do I save a CameraImage to an image file?
body: <p>I developed a mobile application with flutter. I do object detection use &quot;controller.startImageStream&quot; this method return CameraImage and i use with object detection. I want to save this image file. I tried to convert this file to List and jpg file for save. But uint8list could not converted to List. Is this structure a true way? If you know different solutions for my problem, please share me.</p>
  <p>This is my video streaming method ;</p>
  <pre><code>startVideoStreaming() {
      if (cameras == null || cameras.length &lt; 1) {
        print('No camera is found');
      } else {
        controller = new CameraController(
          cameras[0],
            ResolutionPreset.medium,
          );
  
          if(!_busy){
            controller.initialize().then((_) {
  
            print(&quot;model yükleme bitmiş stream dinleme başlıyor &quot;);
  
            controller.startImageStream((CameraImage img){
                    print(&quot;img format: ${img.format} planes: ${img.planes}&quot;);
                    List&lt;int&gt; imageBytes = [];
                    img.planes.map((plane) {
                      imageBytes.addAll(plane.bytes.toList());
                    });
                    
                    // call save image file method
                      saveImageFile(imageBytes).then((res) =&gt; {
                        print(&quot;save image file successfull filepath: $res&quot;)
                      }).catchError((err) =&gt; {
                        print(&quot;error on save image file error: $err&quot;)
                      });
                    
                    if(!isDetecting){
                      isDetecting = true;
                      print(&quot;Tflite'a stream gönderildi&quot;);
                      Tflite.detectObjectOnFrame(
                          bytesList: img.planes.map((plane) {
                            return plane.bytes;
                          }).toList(),
                          model: &quot;SSDMobileNet&quot;,
                          imageHeight: img.height,
                          imageWidth: img.width,
                          imageMean: 127.5,
                          imageStd: 127.5,
                          numResultsPerClass: 1,
                          threshold: 0.4,
                        ).then((recognitions) {
                          int endTime = new DateTime.now().millisecondsSinceEpoch;
                          setState(() {
                            _recognitions=recognitions;
                          });
                          print(&quot;Recognitions: $recognitions&quot;);
                          isDetecting = false;
                        });
                    }
                  });
            });
          }
      }
    }
  </code></pre>
  <p>This is my image save method ;</p>
  <pre><code>Future&lt;String&gt; saveImageFile(imageBytes) async {
      final Directory extDir = await getApplicationDocumentsDirectory();
      final String dirPath = '${extDir.path}/Pictures/flutter_test';
      await Directory(dirPath).create(recursive: true);
      final String filePath = '$dirPath/${timestamp()}.jpg';
  
      if (controller.value.isTakingPicture) {
        // A capture is already pending, do nothing.
        return null;
      }
  
      try {
        File file = new File(filePath);
        file.writeAsBytes(imageBytes);
        print(&quot;finish image saved $imageBytes&quot;);
      } on CameraException catch (e) {
        _showCameraException(e);
        return null;
      }
      return filePath;
    }
  </code></pre>