【发布时间】:2014-01-02 10:21:57
【问题描述】:
如何将 char buffer 转换为 unsigned short int newBuffer? 以下是我的代码:
另外,在生成的新缓冲区中,如何获取大小。 我正在读取 char buffer 中的图像文件,为了进一步处理,我想将此 char 转换为 unsigned short int *。 请有人帮我解决这个问题
FILE * pFile;
long lSize;
char * buffer;
size_t result;
pFile = fopen ( "d:\\IMG1" , "rb" );
if (pFile==NULL) {fputs ("File error",stderr); exit (1);}
// obtain file size:
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
// allocate memory to contain the whole file:
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
// copy the file into the buffer:
result = fread (buffer,1,lSize,pFile);
if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
/* the whole file is now loaded in the memory buffer. */
// terminate
fclose (pFile);
unsigned short int *shBuffer = (unsigned short int *)buffer;
int jp2shortsize = sizeof(*shBuffer);
free (buffer);
【问题讨论】:
-
看起来更像 C 代码,你确定要 C++ 答案吗?
-
您面临的具体问题是什么?
标签: c++