1

我正在使用OV7670ESP32捆绑包做一个 wifi 相机项目:https ://github.com/bitluni/ESP32CameraI2S 。

如何使用SPIFFSin保存位图File

部分代码:

void Get_photo (AsyncWebServerRequest * request) {
   camera-> oneFrame ();
   File file = SPIFFS.open ("/ Images / test.bmp", FILE_WRITE); // How to save to this file?

   for (int i = 0; i <BMP :: headerSize; i ++)
   {
       bmpHeader [i];
   }

   for (int i = 0; i <camera-> xres * camera-> yres * 2; i ++)
   {
      camera-> frame [i];
   }


  Serial.println ("PHOTO_OK!");
}
4

1 回答 1

1

不确定您是否仍然需要答案,但它可能会对某人有所帮助。您正在读取这些值,但没有将其写入文件。

void Get_photo (AsyncWebServerRequest * request) {

  camera-> oneFrame ();
  File file = SPIFFS.open ("/ Images / test.bmp", FILE_WRITE); // Here the file is opened

  if (!file) {
    Serial.println("Error opening the file."); // Good practice to check if the file was correctly opened
    return; // If file not opened, do not proceed
  }

  for (int i = 0; i <BMP :: headerSize; i ++)
  {
    file.write(bmpHeader [i]); // Writes header information to the BMP file
  }

  for (int i = 0; i <camera-> xres * camera-> yres * 2; i ++)
  {
    file.write(camera-> frame [i]); // Writes pixel information to the BMP file
  }

  file.close(); // Closing the file saves its content

  Serial.println ("PHOTO_OK!");

}

请记住,每次调用时Get_photo,它都会覆盖test.bmp,因为两个文件不能具有相同的名称。

希望对某人有所帮助。

于 2019-07-08T20:17:10.947 回答