mercredi 29 novembre 2023

how store an image into buffer c++

Hello a camera in my project used to get a pictur and stored it in buffer and then send it to    serverusing c++ language.i have writed this code but the output of buffer  give me this result :

"vØ~Çš_GÙœunô@FUÁs´ò¤Ë°±tF~'µÎF¿>`ðóvC™fÏÃVÔe>kŸlŠÜœ¬4í&΂ž·z>µ£±Ôÿ *ná3ÂJ18 î”!"

but i want the output of the my buffer like this 0x11 ,0x22.....

someone can help please ?

C++ CODE:

#include <iostream>
#include <fstream>
#include <string.h>
#include<vector>
#include <stdio.h>
using namespace std ;
int main() {

 ifstream ifd("C:/Users/GhadaM/Desktop/ghada.jpg",std::ifstream::binary | std::ifstream::in);
 int size = ifd.tellg();
 ifd.seekg(0, ios::beg);
 vector<char> buffer;
 buffer.resize(size); // << resize not reserve
 ifd.read(buffer.data(), size);
 for (char i: buffer)
{ 
  std::cout \<\< i;
}
}

** the ouput:**

Çš_GÙœunô@FUÁs´ò¤Ë°±tF~'µÎF¿>`ðóvC™fÏÃVÔe>kŸlŠÜœ¬4í&΂ž·z>µ£±Ôÿ *ná3ÂJ18 î”!

expected result is:

0x11 ,0x22.....

Aucun commentaire:

Enregistrer un commentaire