February 22nd, 2007, 05:36 AM
#1
Rotate Emf with Gradient
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
Attached Files
February 22nd, 2007, 06:46 AM
#2
Re: Rotate Emf with Gradient
If I desactivate the ModifyworldTransform calls the output is OK?
Thank you
February 23rd, 2007, 04:53 AM
#3
Re: Rotate Emf with Gradient
Hi
Now I can get it to work when drawing to emf file, but not on printer...
I replace the playmetafile by an EnumEnhMetaFile with the folowing EMFProc, its better but it doesn't work on printer when paper size is large (A0 for exemple) and it works on A4?
Code:
int CALLBACK EMFProc(HDC hDC, HANDLETABLE *pHTable,
const ENHMETARECORD *pEMFR, int nObj, LPARAM lpData)
{
int nRet = 1;
switch(pEMFR->iType)
{
case EMR_STRETCHDIBITS:
{
const EMRSTRETCHDIBITS * pStretchDIBits = (const EMRSTRETCHDIBITS *)pEMFR;
nRet = StretchDIBits(hDC,
pStretchDIBits->xDest,
pStretchDIBits->yDest,
pStretchDIBits->cxDest,
pStretchDIBits->cyDest,
pStretchDIBits->xSrc,
pStretchDIBits->ySrc,
pStretchDIBits->cxSrc,
pStretchDIBits->cySrc,
(const BYTE *)pEMFR + pStretchDIBits->offBitsSrc,
(const BITMAPINFO *)((const BYTE *)pEMFR + pStretchDIBits->offBmiSrc),
pStretchDIBits->iUsageSrc,
pStretchDIBits->dwRop);
}
break;
default:
nRet = PlayEnhMetaFileRecord(hDC,pHTable,pEMFR,nObj);
}
return nRet;
}
EnumEnhMetaFile(hDC,hemf,EMFProc,NULL,lpRect);
Thank you
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width