阅读骨形态发生蛋白灰度标尺为C [英] Read Bmp Greyscales into C

查看:133
本文介绍了阅读骨形态发生蛋白灰度标尺为C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找了如何读取BMP文件转换为C的第2或1维数组,有很多解决方案,但不是我所需要的。
我需要阅读的黑白BMP成(以初学者)2维数组它必须从0包含值255(灰度)
然后将其转换成一维数组(但是这不是一个问题)。
Matlab的做到这一点automticly但我想更自主的在C / C ++的工作
在最后的BMP应当保存到数据库Postgre int数组。
谢谢

I looked for how to read a Bmp file into a 2 or 1 dimensional Array under C , there are many solutions but not the one i need. I need to read the Black and white bmp into (to beginn) 2 dimensional array which have to contain values from 0 to 255 (greyscale) and then transform it to 1 dimensional array(but that's not a problem). Matlab does this automticly but i want to be more autonomous working under C/C++ at the end the bmp shall be saved into a Postgre Database int array. Thanks

推荐答案

还有我另一个SO问题做了一个BMP装载机:结果
http://nishi.dreamhosters.com/u/so_bmp_v0.zip 结果
这个例子BMP有RGB,但似乎与灰阶到正常工作。

There's a bmp loader which I made for another SO question:
http://nishi.dreamhosters.com/u/so_bmp_v0.zip
The example bmp there is RGB, but it seems to work with grayscale as well.

FILE* f = fopen( "winnt.bmp", "rb" ); if( f==0 ) return 1;
fread( buf, 1,sizeof(buf), f );
fclose(f);

BITMAPFILEHEADER& bfh = (BITMAPFILEHEADER&)buf[0];
BITMAPINFO& bi = (BITMAPINFO&)buf[sizeof(BITMAPFILEHEADER)];
BITMAPINFOHEADER& bih = bi.bmiHeader; 
char* bitmap = &buf[bfh.bfOffBits];
int SX=bih.biWidth, SY=bih.biHeight;

位图的这里的指针像素表(应无符号
为适当的访问虽然)。注意,在BMP该像素行可以存储在
相反的顺序。

bitmap here is the pointer to the pixel table (should be made unsigned for proper access though). Note that pixel rows in bmp can be stored in reverse order.

这篇关于阅读骨形态发生蛋白灰度标尺为C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆