求助,提供方向也行,图片显示

风拂林 2012-08-29 07:15:30
一幅图片,用char* buffer存储,三个字符RGB为一个像素,这样的存法,有没人弄过?我想找个方法把它显示出来,验证我写的算法是否正确

限制要求是win32,非MFC

有代码提供是最好了。。。没有的话,搜索的关键字也行的。。
...全文
58 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
风拂林 2012-09-19
  • 打赏
  • 举报
回复
上面几个方法都没用成,win的api太复杂。。。不确定哪个才是正确的
schlafenhamster 2012-08-29
  • 打赏
  • 举报
回复
你那个(这样的存法)已经存为文件了吧,
显示时读回数据,即bits。
按你知道的信息(高宽。。。)填一个:BMPinfo
再调用StretchDIBits
就可以了。
风拂林 2012-08-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

StretchDIBits
The StretchDIBits function copies the color data for a rectangle of pixels in a device-independent bitmap (DIB) to the specified destination rectangle. If the destination rectangle is ……
[/Quote]

我就是从画布上拿下来的buffer但画布往哪去打印,这个不会。。
风拂林 2012-08-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

pBits就是你说的char* buffer

代码是MFC图像保存改编过来的。没测试,这是流程。

C/C++ code

//图形格式参数
LPBITMAPINFO lpbmih = new BITMAPINFO;
lpbmih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
……
[/Quote]

file是fstream?类型写入写不进去。。
schlafenhamster 2012-08-29
  • 打赏
  • 举报
回复
StretchDIBits
The StretchDIBits function copies the color data for a rectangle of pixels in a device-independent bitmap (DIB) to the specified destination rectangle. If the destination rectangle is larger than the source rectangle, this function stretches the rows and columns of color data to fit the destination rectangle. If the destination rectangle is smaller than the source rectangle, this function compresses the rows and columns by using the specified raster operation.

pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits(pDC->GetSafeHdc(),xStart,yStart,width,height,
0,0,width,height,
bitsAt,
//&BmpInfo,//without RGBQUAD
(BITMAPINFO *)pBMPinfo,// has RGBQUAD
DIB_RGB_COLORS,SRCCOPY);
傻X 2012-08-29
  • 打赏
  • 举报
回复
pBits就是你说的char* buffer

代码是MFC图像保存改编过来的。没测试,这是流程。


//图形格式参数
LPBITMAPINFO lpbmih = new BITMAPINFO;
lpbmih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpbmih->bmiHeader.biWidth = iWidth;
lpbmih->bmiHeader.biHeight = iHeight;
lpbmih->bmiHeader.biPlanes = 1;
lpbmih->bmiHeader.biBitCount = iPixel;
lpbmih->bmiHeader.biCompression = BI_RGB;
lpbmih->bmiHeader.biSizeImage = 0;
lpbmih->bmiHeader.biXPelsPerMeter = 0;
lpbmih->bmiHeader.biYPelsPerMeter = 0;
lpbmih->bmiHeader.biClrUsed = 0;
lpbmih->bmiHeader.biClrImportant = 0;


//保存到文件并创建位图结构
BITMAPFILEHEADER bmfh;
ZeroMemory(&bmfh,sizeof(BITMAPFILEHEADER));
*((char *)&bmfh.bfType) = 'B';
*(((char *)&bmfh.bfType) + 1) = 'M';
bmfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmfh.bfSize = bmfh.bfOffBits + (iWidth * iHeight) * iPixel / 8;
TCHAR szBMPFileName[128];
int iBMPBytes = iWidth * iHeight * iPixel / 8;

file.Write(&bmfh,sizeof(BITMAPFILEHEADER));
file.Write(&(lpbmih->bmiHeader),sizeof(BITMAPINFOHEADER));
file.Write(pBits,iBMPBytes);
file.Close();

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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