我正在做一个使用OV7670和ESP32捆绑包的wifi摄像头项目:https://github.com/bitluni/ESP32CameraI2S。
如何在File中使用SPIFFS保存位图?
代码的一部分:
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!");
}发布于 2019-07-09 04:17:11
不确定你是否还需要答案,但它可能会对某人有所帮助。您正在读取值,但没有将其写入文件。
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,因为两个文件不能同名。
希望这能帮助到一些人。
https://stackoverflow.com/questions/53036361
复制相似问题