c语言读raw图像并统计直方图,小弟我又重写了一个。
c语言读raw图像并统计直方图,我又重写了一个。。。。【急】
望指教。。。。。。。~~o(>_<)o ~~
#include<stdio.h>
#include<stdlib.h>
//#include<string.h>
int *value=new int[256*256]; //存像素的数组空间
void OpenDat()//打开文件(图像)
{
FILE *fp;
if((fp=fopen("E:\\Lena.raw","rw"))==NULL)
exit(0);
// return true;
}
bool ReadDat()//读图像
{
FILE *fp;
int i,j;
for(i=0;i<256;i++)
for(j=0;j<256;j++)
{
if(fread(&value[i][j],8,256,fp)!=1) //这样写对不对?
printf("error\n");
}
fclose(fp);
}
bool WriteDat()
{
FILE *fp;
int i,j,k;
if((fp=fopen("E:\\result.txt","rw"))==NULL)
exit(0);
for(i=0;i<256;i++)
for(j=0;j<256;j++)
{
fwrite(&value[i][j],8,256,fp);
}
for(k=0;k<256;k++)
{
printf("%d\t%f",k,value);
}
}
void main()
{
// int * value[256][256]=new int[256*256];
OpenDat();
ReadDat();
WriteDat();
delete[] value;
}
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.cpp
E:\zz\zz\test\test.cpp(20) : error C2109: subscript requires array or pointer type
E:\zz\zz\test\test.cpp(20) : error C2102: '&' requires l-value
E:\zz\zz\test\test.cpp(36) : error C2109: subscript requires array or pointer type
E:\zz\zz\test\test.cpp(36) : error C2102: '&' requires l-value
Error executing cl.exe.
test.obj - 4 error(s), 0 warning(s)
------解决方案--------------------
[code=C/C++][/code]
for(i=0;i<(256*256);i++)
{
if(fread(&value[i],sizeof(int),1,fp)!=1) //这样写对不对?
printf("error\n");
}
一下子全读过来多好
if(fread(value,sizeof(int),256*256,fp)!=1)
望指教。。。。。。。~~o(>_<)o ~~
#include<stdio.h>
#include<stdlib.h>
//#include<string.h>
int *value=new int[256*256]; //存像素的数组空间
void OpenDat()//打开文件(图像)
{
FILE *fp;
if((fp=fopen("E:\\Lena.raw","rw"))==NULL)
exit(0);
// return true;
}
bool ReadDat()//读图像
{
FILE *fp;
int i,j;
for(i=0;i<256;i++)
for(j=0;j<256;j++)
{
if(fread(&value[i][j],8,256,fp)!=1) //这样写对不对?
printf("error\n");
}
fclose(fp);
}
bool WriteDat()
{
FILE *fp;
int i,j,k;
if((fp=fopen("E:\\result.txt","rw"))==NULL)
exit(0);
for(i=0;i<256;i++)
for(j=0;j<256;j++)
{
fwrite(&value[i][j],8,256,fp);
}
for(k=0;k<256;k++)
{
printf("%d\t%f",k,value);
}
}
void main()
{
// int * value[256][256]=new int[256*256];
OpenDat();
ReadDat();
WriteDat();
delete[] value;
}
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.cpp
E:\zz\zz\test\test.cpp(20) : error C2109: subscript requires array or pointer type
E:\zz\zz\test\test.cpp(20) : error C2102: '&' requires l-value
E:\zz\zz\test\test.cpp(36) : error C2109: subscript requires array or pointer type
E:\zz\zz\test\test.cpp(36) : error C2102: '&' requires l-value
Error executing cl.exe.
test.obj - 4 error(s), 0 warning(s)
------解决方案--------------------
[code=C/C++][/code]
for(i=0;i<(256*256);i++)
{
if(fread(&value[i],sizeof(int),1,fp)!=1) //这样写对不对?
printf("error\n");
}
一下子全读过来多好
if(fread(value,sizeof(int),256*256,fp)!=1)