将Raw12文件中的图像数据读入Buffer C ++

时间:2018-02-27 10:36:30

标签: c++ image-processing

我在处理这种文件时有点新意。我想将Raw12中的图像日期读入缓冲区。之后,我将12位文件转换为8位。所以,我偶然发现了一个代码,我想知道有更好的方法吗?

ifstream rawImage (fileName, ifstream::binary);
if (rawImage) {
    // Gets length of file.
    rawImage.seekg(0, rawImage.end);
    uint32_t length = rawImage.tellg();
    rawImage.seekg(0, rawImage.beg);

    // Allocates memory and stores the file info into a buffer.
    uint8_t * bufferImage = new uint8_t[length];
    rawImage.read(reinterpret_cast<char*>(bufferImage), length);

    // Closes file.
    rawImage.close();

    // Array for storing the sensor information from the file.
    uint8_t * arrayImage = new uint8_t[4096*3072];

感谢您的帮助。

编辑: -

阅读评论后,我重新编写了代码。这会好吗?有什么遗漏吗?

      #include<iostream>
      #include<fstream>
      #include<sstream>
      #include<string.h>
      #include "LodePNG/lodepng.h"
      #include<cstdio>
      #include<cmath>
      #include<vector>
      #include <stdlib.h>

      using namespace std;

      const int BUFFERSIZE = 4096;   

      int main(int argc, char** argv)
     {
       if( argc != 2)
      {
 cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
 return -1;
}

  //Reading Raw12 file
   const char * fName = "filename.raw12";
   std::ifstream file(fName, std::ios::binary|std::ios::in);
   if (!file) { 
    printf("Error: could not open file %s\n", fName); return -1; }

   //Reading into Buffer

        uint32_t * buffer = new uint32_t [BUFFERSIZE];


      }

0 个答案:

没有答案