怎么用C++修改BMP位图的RGB三色

bjcm19901020 2011-09-04 09:11:24
求用C++编写一个程序可以读取BMP位图,然后可以修改BMP位图的RGB三色,最后保存退出。请高手能给出详细的程序,感激不敬
...全文
720 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ryfdizuo 2011-09-05
  • 打赏
  • 举报
回复
GetDIBits这个函数就可以。
codeproject上有一个CBitmapEx是基于GDI的,功能着实强悍。。。
http://www.codeproject.com/KB/graphics/CBitmapEx.aspx#
TOOCROWN 2011-09-05
  • 打赏
  • 举报
回复
1.将当前bmp文件读入到一个buffer,这个buffer为当前BMP的文件大小(fopen,fread函数)
2.了解当前BMP的格式(一般为文件头,信息头,调色板,RGB(或者灰度图)),输出(int)buffer[14+4]即为图像的宽,依次了解BMP的格式
3.指针指向RGB数值区域
4.修改RGB数值区域
5.保存(fwrite)
没有昵称阿 2011-09-05
  • 打赏
  • 举报
回复
要不调用库函数,用纯C++写的话,先得了解bmp图片的格式,然后再去动手编程。
着2片文章你可以看一下:介绍bmp格式的:http://blog.csdn.net/xiajun07061225/article/details/5813726
然后是一个读取bmp图片与保存bmp图片的实例:http://blog.csdn.net/xiajun07061225/article/details/6633938
相信会对你有用~~~
jackyjkchen 2011-09-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 babilife 的回复:]

看这篇文章,讲得不错

http://www.cnblogs.com/lyy289065406/archive/2011/08/25/2153030.html
[/Quote]
看看吧
至善者善之敌 2011-09-04
  • 打赏
  • 举报
回复
月中蓝 2011-09-04
  • 打赏
  • 举报
回复
BITMAP结构的bmBits就是颜色数据
用LoadImage得到HBITMAP句柄,然后GetObject得到BITMAP,对bmBits进行处理,再保存就可以
Gloveing 2011-09-04
  • 打赏
  • 举报
回复
利用API函数:
1.先加载位图:LoadBitmap
The LoadBitmap function loads the specified bitmap resource from a module's executable file. This function has been superseded by theLoadImage function.

HBITMAP LoadBitmap(
HINSTANCE hInstance, // handle to application instance
LPCTSTR lpBitmapName // address of bitmap resource name
);

2.GetDIBits
The GetDIBits function retrieves the bits of the specified bitmap and copies them into a buffer using the specified format.

int GetDIBits(
HDC hdc, // handle to device context
HBITMAP hbmp, // handle to bitmap
UINT uStartScan, // first scan line to set in destination bitmap
UINT cScanLines, // number of scan lines to copy
LPVOID lpvBits, // address of array for bitmap bits
LPBITMAPINFO lpbi, // address of structure with bitmap data
UINT uUsage // RGB or palette index
);


[color=#FF0000]3.BITMAPINFO

The BITMAPINFO structure defines the dimensions and color information for a Win32 device-independent bitmap (DIB).

typedef struct tagBITMAPINFO { // bmi
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO

4.RGBQUAD
The RGBQUAD structure describes a color consisting of relative intensities of red, green, and blue.

typedef struct tagRGBQUAD { // rgbq
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD


5.修改 BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
中的值

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧