社区
图形处理/算法
帖子详情
已知 RGB24 数据、长、宽,如何保存为BMP文件,请具体的讲,最好有代码
aa3000
2004-12-03 04:53:01
已知 RGB24 数据、长、宽,如何保存为BMP文件,请具体的讲,最好有代码
...全文
303
5
打赏
收藏
已知 RGB24 数据、长、宽,如何保存为BMP文件,请具体的讲,最好有代码
已知 RGB24 数据、长、宽,如何保存为BMP文件,请具体的讲,最好有代码
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
DentistryDoctor
2004-12-03
打赏
举报
回复
如果是RGB24/RGB16话,前面是一个文件头,后面就是位数据。
DentistryDoctor
2004-12-03
打赏
举报
回复
CFile fileBmp;
if(fileBmp.Open("Hello.bmp",CFile::modeWrite |CFile::shareExclusive | CFile::modeCreate))
{
BITMAPINFOHEADER fmtFrame = {sizeof(BITMAPINFOHEADER), 0, 0, 1, 24, BI_RGB, 0, 0, 0, 0, 0};
fmtFrame.biWidth = w;
fmtFrame.biHeight = h;
fmtFrame.biSizeImage =(w+3)/4*4*h*3;
BITMAPFILEHEADER fInfo;
ZeroMemory(&fInfo, sizeof fInfo);
fInfo.bfType = 0x4D42;
fInfo.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
fInfo.bfSize = fInfo.bfOffBits + fmtFrame.biSizeImage;
fileBmp.Write(&fInfo, sizeof fInfo);
fileBmp.Write(&fmtFrame,sizeof(fmtFrame));
fileBmp.Write(pBits,fmtFrame.biSizeImage);
}
fileBmp.Close();
aa3000
2004-12-03
打赏
举报
回复
关键是我不知道 RGB 数据格式和 BMP 文件格式是什么关系.请教
老夏Max
2004-12-03
打赏
举报
回复
我是创建一个随机象素的BMP,RGB值是使用GetRandomRGBValue获得的一个随机数的!
老夏Max
2004-12-03
打赏
举报
回复
参考:
void CCreateRandomBMPDlg::OnBtnCreateBMP()
{
CDC dc;
dc.CreateDC("DISPLAY", NULL, NULL, NULL);
CBitmap bm;
int Width = 800;//GetSystemMetrics(SM_CXSCREEN);
int Height = 600;//GetSystemMetrics(SM_CYSCREEN);
bm.CreateCompatibleBitmap(&dc, Width, Height);
CDC tdc;
tdc.CreateCompatibleDC(&dc);
CBitmap* pOld = tdc.SelectObject(&bm);
tdc.BitBlt(0, 0, Width, Height, &dc, 0, 0, SRCCOPY);
tdc.SelectObject(pOld);
BITMAP btm;
bm.GetBitmap(&btm);
DWORD size = btm.bmWidthBytes* btm.bmHeight;
LPSTR lpData = (LPSTR) GlobalAllocPtr(GPTR, size);
/////////////////////////////////////////////
/////////////////////////////////////////////
BITMAPINFOHEADER bih;
bih.biBitCount = btm.bmBitsPixel;
bih.biClrImportant = 0;
bih.biClrUsed = 0;
bih.biCompression = 0;
bih.biHeight = btm.bmHeight;
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = size;
bih.biWidth = btm.bmWidth;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
///////////////////////////////////
GetDIBits(dc, bm, 0, bih.biHeight, lpData, (BITMAPINFO *) &bih,
DIB_RGB_COLORS);
// bm.GetBitmapBits(size,lpData); //此函数在处理5-5-5模式的16位色下会出现颜色混乱
//////////////////////////////
//修改RGB值
int nWidth = btm.bmWidth * 4;
for (int i = 0; i < btm.bmHeight; i++)
{
for (int j = 0; j < btm.bmWidth; j++)
{
lpData[i * nWidth + j * 4 + 2] = GetRandomRGBValue(); //R
lpData[i * nWidth + j * 4 + 1] = GetRandomRGBValue(); //G
lpData[i * nWidth + j * 4] = GetRandomRGBValue(); //B
TRACE("\nR = %d; G = %d; B = %d\n",
lpData[i * nWidth + j * 4 + 2],
lpData[i * nWidth + j * 4 + 1], lpData[i * nWidth + j * 4]);
}
}
static int filecount = 0;
CString name;
name = "D:\\Test.bmp";//m_Path+name;
BITMAPFILEHEADER bfh;
bfh.bfReserved1 = bfh.bfReserved2 = 0;
bfh.bfType = ((WORD) ('M' << 8) | 'B');
bfh.bfSize = 54 + size;
bfh.bfOffBits = 54;
CFile bf;
if (bf.Open(name, CFile::modeCreate | CFile::modeWrite))
{
bf.WriteHuge(&bfh, sizeof(BITMAPFILEHEADER));
bf.WriteHuge(&bih, sizeof(BITMAPINFOHEADER));
bf.WriteHuge(lpData, size);
bf.Close();
}
GlobalFreePtr(lpData);
AfxMessageBox("Create BMP File Over!");
}
将
数据
保存
为
BMP
实例
将图像
数据
保存
为
BMP
,比如
RGB
保存
为
BMP
图片!
BMP
.rar_bitmap read c source_
bmp
读写_
bmp
文件
_c
bmp
_写
bmp
C语言环境
代码
下读写
BMP
文件
代码
,运行的时候在vc6.0下通过.
BMP
测试图片及显示源码
BMP
测试图片及显示源码,Linux测试
代码
,附带标准测试图片。
bmp
2.rar_
bmp
2_位图
数据
读图,读任意位的
bmp
图像,显示其位图信息头,位图
数据
等
图形处理/算法
19,472
社区成员
50,678
社区内容
发帖
与我相关
我的任务
图形处理/算法
VC/MFC 图形处理/算法
复制链接
扫一扫
分享
社区描述
VC/MFC 图形处理/算法
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章