//保存到磁盘上的png文件
int iWidth = m_FrameBuffer.m_iSizeX;
int iHight = m_FrameBuffer.m_iSizeY;
CImage Image;
//必须用这个CreatEx
Image.CreateEx(iWidth, -iHight, 32, BI_RGB, NULL, 0x000000FF);
byte* fromByte = m_FrameBuffer.m_pBits;
int nPitch = Image.GetPitch(), nBPP = Image.GetBPP();
LPBYTE lpBits = reinterpret_cast(Image.GetBits());
for (int yPos = 0; yPos < iHight; yPos++)
{
LPBYTE lpBytes = lpBits + (yPos * nPitch);
byte* toByte = lpBytes;
for (int xPos = 0; xPos < iWidth * 4; xPos++)
{
toByte[xPos] = fromByte[yPos *iWidth * 4 + xPos];
}
}
Image.Save(_T(“C:\Users\17691\Desktop\2.png”), ImageFormatPNG);
Image.Detach();
https://docs.microsoft.com/zh-cn/cpp/atl-mfc-shared/reference/cimage-class?view=vs-2019#createex