首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用OV7670 ESP32和SPIFFS保存位图?

如何使用OV7670 ESP32和SPIFFS保存位图?
EN

Stack Overflow用户
提问于 2018-10-29 05:43:26
回答 1查看 904关注 0票数 1

我正在做一个使用OV7670ESP32捆绑包的wifi摄像头项目:https://github.com/bitluni/ESP32CameraI2S

如何在File中使用SPIFFS保存位图?

代码的一部分:

代码语言:javascript
复制
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!");
}
EN

回答 1

Stack Overflow用户

发布于 2019-07-09 04:17:11

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

代码语言:javascript
复制
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,因为两个文件不能同名。

希望这能帮助到一些人。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53036361

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档