我完全是初学者。我将尽我所能解释清楚。
int i, j;
string filename;
cout << "Please enter the file name: " << endl;
cin >> filename;
fstream stream;
stream.open(filename.c_str(),
ios::in|ios::out|ios::binary);
int file_size = get_int(stream, 2);
int start = get_int(stream, 10);
int width = get_int(stream, 18);
int height = get_int(stream, 22);
这个部分应该得到文件和它的值。
for ( i = 0; i < height; i++ )
{
for ( j = 0; j < width; j++)
{
for (int k = 0; k < split*split; k++){
int pos = stream.tellg();
int blue = stream.get();
int green = stream.get();
int red = stream.get();
到达每个像素内部并获得RBG值。
我想要的是首先将RBG值存储到2D数组中,然后对该数组进行一些操作。然后我想创建一个新的文件与处理图像。
我没有线索,所以一些指令和一些代码将是非常有用的。
Bmp文件格式在许多地方都有文档。例如,在维基百科上
最简单的方法是实现描述bmp头的结构,并一次读取整个结构,然后读取单个像素。
你的读取函数坏了,不能工作,因为你没有读取头文件签名- "BM"字段。
在某些操作系统中,已经有读取bmp的结构和函数。在windows上,有BITMAPFILEHEADER。使用这些结构意味着你不是在使用"纯c++"。
如果你仍然想自己阅读BMP,可以阅读有关BMP的msdn文章或谷歌"阅读BMP文件"教程。
这个库非常容易使用http://easybmp.sourceforge.net/。你可以在加载文件后方便地检查RGB值