bitmap from clipboard to file
"umeca74" <[email protected]>
| Newsgroups | gmane.comp.windows.wtl |
|---|---|
| Message-ID | <[email protected]> |
Hi
I've been trying to save a window snapshot (32-bit) to a BMP file, but the saved image is slightly distorted, it looks like the picture is shifted to the right by a few pixels, like this:
http://img97.imageshack.us/img97/5189/clipboard01e.png
here is the code i use (stripped from error checks). It must be something silly I do but after 2 days I can't see what!?
--------------------------------
LPDATAOBJECT pDataObject;
OleGetClipboard(&pDataObject);
FORMATETC fmt = {CF_DIB, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
STGMEDIUM stgm;
pDataObject->GetData(&fmt, &stgm);
file = root + _T("x2scrap.bmp");
HANDLE hOut = CreateFile(file, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
LPBITMAPINFOHEADER hDIB = (LPBITMAPINFOHEADER)GlobalLock(stgm.hGlobal);
BITMAPFILEHEADER bmh;
DWORD sizebm = GlobalSize(stgm.hGlobal); // includes palettes
bmh.bfType = MAKEWORD('B', 'M');
bmh.bfReserved1 = 0;
bmh.bfReserved2 = 0;
bmh.bfOffBits = sizeof(bmh) + hDIB->biSize;
if(hDIB->biBitCount <= 8) { // palette exists
DWORD tmp = hDIB->biClrUsed;
if(!tmp)
tmp = 1 << hDIB->biBitCount;
bmh.bfOffBits += tmp*sizeof(RGBQUAD);
}
bmh.bfSize = sizebm + sizeof(bmh);
DWORD ioAmount;
WriteFile(hOut,&bmh,sizeof(bmh),&ioAmount,NULL);
WriteFile(hOut,hDIB,sizebm,&ioAmount,NULL);
GlobalUnlock(stgm.hGlobal);
CloseHandle(hOut);
ReleaseStgMedium(&stgm);
pDataObject->Release();
--------------------------------
any help appreciated
thanks
nikos
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/wtl/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/wtl/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[email protected]
mailto:[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/