Converting SVG images
Posted: 21 Apr 2010, 20:20
Hello,
we want to use CAD Image Dll to convert svg images. The following is a code fragment to export the svg as bmp-file.
But the quality of the exported image is not good. See the attached files (original svg- and exported bmp-file).
Is there anything we can improve here?
Also we found a function that returns a DIB directly (HGLOBAL DrawCADtoDIB( HANDLE Handle,LPRECT R);)
But the returned DIB is 8-bit. Is it possible to get a 24-bit DIB?
Best regards
Martin
--------------------------------------------------------------------
code fragment:
BOOL bRet= pf_STRG(lic_name,lic_email,lic_code);
HANDLE hCAD= pf_CreateCAD(NULL,pszSource);
if (hCAD)
{
float fAbsWidth, fAbsHeight;
if (pf_GetBoxCAD(hCAD, &fAbsWidth, &fAbsHeight))
{
int nW= (int)(fAbsWidth+0.5);
int nH= (int)(fAbsHeight+0.5);
int bits_per_pixel= 24;
HDC hDC= ::GetDC(NULL);
HDC hDCMem= ::CreateCompatibleDC(hDC);
CADDRAW cd= {0};
cd.Size = sizeof(cd);
cd.DrawMode = dmNormal;
cd.R.left = 0;
cd.R.right = nW;
cd.R.top = 0;
cd.R.bottom = nH;
cd.DC = ::CreateCompatibleDC(hDC);
HBITMAP hBitmap= ::CreateCompatibleBitmap( hDC, nW, nH);
HGDIOBJ hOldBmp= ::SelectObject(cd.DC, hBitmap);
::FillRect(cd.DC, &cd.R, (HBRUSH)RGB(255, 255, 255));
bRet = pf_DrawCADEx(hCAD, &cd);
if (bRet)
{
HANDLE hDIB= ::CreateDIB(nW,nH,bits_per_pixel);
LPBITMAPINFO pBI= (LPBITMAPINFO)::GlobalLock(hDIB);
::GetDIBits(cd.DC,hBitmap,0,nH,::find_DIB_bits(pBI),pBI,DIB_RGB_COLORS);
::GlobalUnlock(hDIB);
::WriteDIB(strTarget,hDIB);
::GlobalFree(hDIB);
}
::SelectObject(cd.DC, hOldBmp);
::DeleteObject(hBitmap);
::DeleteDC(cd.DC);
::ReleaseDC(NULL,hDC);
}
pf_CloseCAD(hCAD);
}
---------------------------------------------------------------
we want to use CAD Image Dll to convert svg images. The following is a code fragment to export the svg as bmp-file.
But the quality of the exported image is not good. See the attached files (original svg- and exported bmp-file).
Is there anything we can improve here?
Also we found a function that returns a DIB directly (HGLOBAL DrawCADtoDIB( HANDLE Handle,LPRECT R);)
But the returned DIB is 8-bit. Is it possible to get a 24-bit DIB?
Best regards
Martin
--------------------------------------------------------------------
code fragment:
BOOL bRet= pf_STRG(lic_name,lic_email,lic_code);
HANDLE hCAD= pf_CreateCAD(NULL,pszSource);
if (hCAD)
{
float fAbsWidth, fAbsHeight;
if (pf_GetBoxCAD(hCAD, &fAbsWidth, &fAbsHeight))
{
int nW= (int)(fAbsWidth+0.5);
int nH= (int)(fAbsHeight+0.5);
int bits_per_pixel= 24;
HDC hDC= ::GetDC(NULL);
HDC hDCMem= ::CreateCompatibleDC(hDC);
CADDRAW cd= {0};
cd.Size = sizeof(cd);
cd.DrawMode = dmNormal;
cd.R.left = 0;
cd.R.right = nW;
cd.R.top = 0;
cd.R.bottom = nH;
cd.DC = ::CreateCompatibleDC(hDC);
HBITMAP hBitmap= ::CreateCompatibleBitmap( hDC, nW, nH);
HGDIOBJ hOldBmp= ::SelectObject(cd.DC, hBitmap);
::FillRect(cd.DC, &cd.R, (HBRUSH)RGB(255, 255, 255));
bRet = pf_DrawCADEx(hCAD, &cd);
if (bRet)
{
HANDLE hDIB= ::CreateDIB(nW,nH,bits_per_pixel);
LPBITMAPINFO pBI= (LPBITMAPINFO)::GlobalLock(hDIB);
::GetDIBits(cd.DC,hBitmap,0,nH,::find_DIB_bits(pBI),pBI,DIB_RGB_COLORS);
::GlobalUnlock(hDIB);
::WriteDIB(strTarget,hDIB);
::GlobalFree(hDIB);
}
::SelectObject(cd.DC, hOldBmp);
::DeleteObject(hBitmap);
::DeleteDC(cd.DC);
::ReleaseDC(NULL,hDC);
}
pf_CloseCAD(hCAD);
}
---------------------------------------------------------------