Converting SVG images

Discuss and ask questions about CAD DLL (CAD Image DLL, CAD Importer DLL).

Moderators: SDS, support, admin

Post Reply
martinfischer
Posts: 1
Joined: 21 Apr 2010, 16:21

Converting SVG images

Post by martinfischer » 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);
}
---------------------------------------------------------------
Attachments
Compass.rar
contains the original svg file
(4.52 KiB) Downloaded 2097 times
Compass.svg.rar
contains the converted bmp-file
(52.33 KiB) Downloaded 2132 times

support
Posts: 3253
Joined: 30 Mar 2005, 11:36
Contact:

Re: Converting SVG images

Post by support » 23 Apr 2010, 16:51

Hello.
You can set greater values to nW and nH parameters. This will improve the quality as increase the size. The inner DIB object is 8-bit, however this parameter can be changed if necessary.

Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply