This function is called by my virtual print driver to convert bmp to EMF.
void GetEmfByBytes(BYTE * pBits, int iWidth, int iHeight, WCHAR* szPrinterName, WCHAR* szDestinationFile,DWORD rop=SRCCOPY)
{
BITMAP bm;
HDC hdcMem = CreateCompatibleDC(GetDC(NULL));
HDC hPrinterDC = ::CreateDC(NULL,szPrinterName, NULL, NULL);
BITMAPINFOHEADER bmih;
memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
bmih.biSize = sizeof(BITMAPINFOHEADER);
bmih.biBitCount = 1;
bmih.biCompression = BI_RGB;
bmih.biPlanes = 1;
bmih.biWidth = iWidth;
bmih.biHeight = iHeight;
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader = bmih;
HBITMAP hBmp = ::CreateDIBitmap(hPrinterDC,&bmih,CBM_INIT,pBits,&bmi,0);
GetObject(hBmp, sizeof(BITMAP), &bm );
SelectObject(hdcMem, hBmp);
HDC emfdc = CreateEnhMetaFile(hPrinterDC, szDestinationFile, NULL, L"");
if(emfdc!=NULL){
StretchBlt(emfdc,0, 0, bm.bmWidth, -bm.bmHeight, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, rop); HENHMETAFILE hEMFFile = CloseEnhMetaFile(emfdc); DeleteEnhMetaFile(hEMFFile);
}else{
logOut( wstring(L"can't create emf")+szDestinationFile );
}
DeleteDC(hPrinterDC);
DeleteDC(hdcMem);
DeleteObject(hBmp);
}
anyone knows why? thanks a lot! Please~!