Hi
I want to rotate Emf Images, I am using GDI, winXP.
I can get it to work with most emf images, but recently I detect that when the emf image contain a gradient, the image is rotated but the gradient disappear...
After testing I find that it depends on the size of the output...
I Attached the project which demostrate the problem with corresponding images.
my sample is based on a PrintPic by Feng Yuan
any Idea? what am i doing wrong?
Code:void SavePictureRotate(const TCHAR * pFileName,const TCHAR * pDstFileName, int nMmWidth, int nMmHeight)
{
RECT rcRect;
rcRect.left = 0;
rcRect.top = 0;
rcRect.right = nMmWidth*100;
rcRect.bottom = nMmHeight*100;
::DeleteFile(pDstFileName);
HDC hEmfDC = CreateEnhMetaFile(
NULL,pDstFileName,&rcRect,NULL);
CDC *pDc = CDC::FromHandle(hEmfDC);
int nGraphicMode = pDc->SetGraphicsMode(GM_ADVANCED);
int nMapMode = pDc->SetMapMode( MM_ANISOTROPIC);
float fHorzResolution = (float)pDc->GetDeviceCaps(LOGPIXELSX);
float fVertResolution = (float)pDc->GetDeviceCaps(LOGPIXELSY);
float fMmToPxlHorz = fHorzResolution/25.4f;
float fMmToPxlVert = fVertResolution/25.4f;
float fPxlWidth = (nMmWidth/25.4f*fHorzResolution) / 2.0f;
float fPxlHeight = (nMmHeight/25.4f*fVertResolution) / 2.0f;
XFORM xForm2;
xForm2.eM11 = (FLOAT) 1;
xForm2.eM12 = (FLOAT) 0;
xForm2.eM21 = (FLOAT) 0;
xForm2.eM22 = (FLOAT) 1;
xForm2.eDx = (FLOAT) fPxlWidth / 2.0f;
xForm2.eDy = (FLOAT) fPxlHeight / 2.0f;
BOOL bRet = pDc->ModifyWorldTransform(&xForm2,MWT_LEFTMULTIPLY);
DWORD dwError = GetLastError();
double dAlpha = (360-10) * PI / 180.0;
XFORM xForm3;
xForm3.eM11 = (FLOAT) cos(dAlpha);
xForm3.eM12 = (FLOAT) sin(dAlpha);
xForm3.eM21 = (FLOAT) -sin(dAlpha);
xForm3.eM22 = (FLOAT) cos(dAlpha);
xForm3.eDx = (FLOAT) 0.0;
xForm3.eDy = (FLOAT) 0.0;
bRet = pDc->ModifyWorldTransform(&xForm3,MWT_LEFTMULTIPLY);
HENHMETAFILE hemf = GetEnhMetaFile(pFileName);
RECT rcDest;
rcDest.left = 0;
rcDest.top = 0;
rcDest.right = (int)fPxlWidth; //1000mm
rcDest.bottom = (int)fPxlHeight; //1600mm
pDc->PlayMetaFile(hemf,&rcDest);
DeleteEnhMetaFile(hemf);
HENHMETAFILE hEMF = CloseEnhMetaFile(hEmfDC);
DeleteEnhMetaFile(hEMF);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
SavePictureRotate("./EmfImages/withgradient.emf","./EmfImages/withgradientrotate_1000x1600.emf",1000,1600);
SavePictureRotate("./EmfImages/withoutgradient.emf","./EmfImages/withoutgradientrotate_1000x1600.emf",1000,1600);
SavePictureRotate("./EmfImages/withgradient.emf","./EmfImages/withgradientrotate_100x160.emf",100,160);
SavePictureRotate("./EmfImages/withoutgradient.emf","./EmfImages/withoutgradientrotate_100x160.emf",100,160);
return 0;
}
Thank you
Khaldoun
