【发布时间】:2017-11-13 21:46:03
【问题描述】:
我正在尝试获取AtlImage 的字节缓冲区。类型是CImage
此代码将仅缩放从路径 szFilePath 加载的图像
这里是:
int iNewWidth = 60;
int iNewHeight = 60;
CImage image;
image.Load(szFilePath);
CDC *screenDC = GetDC();
CDC *pMDC = new CDC;
pMDC->CreateCompatibleDC(screenDC);
CBitmap *pb = new CBitmap;
pb->CreateCompatibleBitmap(screenDC, iNewWidth, iNewHeight);
CBitmap *pob = pMDC->SelectObject(pb);
image.StretchBlt(pMDC->m_hDC, 0, 0, iNewWidth, iNewHeight, 0, 0, image.GetWidth(), image.GetHeight(), SRCCOPY);
pMDC->SelectObject(pob);
CImage new_image;
new_image.Attach((HBITMAP)(*pb));
int bytesnbr = abs(new_image.GetPitch()) * new_image.GetHeight();
mSize = bytesnbr;
mBuffer = new BYTE[bytesnbr];
DWORD dwValue = pob->GetBitmapBits(bytesnbr, mBuffer);
new_image.Detach();
ReleaseDC(screenDC);
我遇到了一个异常isDibSection()
我想让缓冲区以base64对其进行编码。
也许还有其他方法......无论如何我需要缩放图像。
感谢您的帮助
【问题讨论】:
-
您所说的“我收到异常
isDibSection()”是什么意思?我没有看到您的代码中提到的那个名称的函数。异常发生在哪里? -
当我调用 GetPitch 时,此异常来自 atlimage.h
-
为什么不使用 Save 方法提供使用 CreateStreamOnHGlobal 创建的 IStream