When an image is scaled, it's scaled as an array of pixels.If the image is really a line graphics, and you want to scale it as vector graphics, convert it to vector form first. You can run some edge detection algorithm on it, thinning the lines, extra the lines, and then scale it.
直接使用api,我的方法只能够处理bmp图 /*----------------------------------------------------------------------------- -Purpose: zoom the picture with specfic ratio -Param : fZoom: ratio -Return : true: successfull; false: failed -Re : here I use m_hOrgBmp as the original bmp, because after zoom in/out the bmp will distortion here I create a hSrcDC to show the original bmp, because it have a infinite size. If we use hDC as the base DC, we may get the wrong part of the screen! _Note : This function will set active bmp with orignal bmp, so if you have changed the active bmp, all the modification will be losed! -----------------------------------------------------------------------------*/ bool CRobinBMP::ZoomBMP(float fZoom) { HDC hDC = GetDC(m_hWnd); HDC hSrcDC = CreateCompatibleDC(hDC); HDC hDstDC = CreateCompatibleDC(hDC); HBITMAP hDstBmp, hOldBmp; int nWidth, nHeight; BITMAP bmp; if (hDstDC==NULL || hSrcDC==NULL) return false; if (GetObject(m_hOrgBmp, sizeof(bmp), &bmp) != 0) { nWidth = bmp.bmWidth; nHeight = bmp.bmHeight; SelectObject(hSrcDC, m_hOrgBmp); // load bmp in src dc hDstBmp = CreateCompatibleBitmap(hDC, nWidth*fZoom, nHeight*fZoom); hOldBmp = (HBITMAP)SelectObject(hDstDC, hDstBmp); StretchBlt(hDstDC, 0, 0, nWidth*fZoom, nHeight*fZoom, hSrcDC, 0, 0, nWidth, nHeight, SRCCOPY); // hDstBmp = (HBITMAP)SelectObject(hDstDC, hOldBmp); hDstBmp = (HBITMAP)GetCurrentObject(hDstDC, OBJ_BITMAP); DeleteObject(hDstDC); DeleteObject(hSrcDC); DeleteObject(m_hBmp); m_hBmp = hDstBmp; return true; } return false; }
/*-----------------------------------------------------------------------------
-Purpose: zoom the picture with specfic ratio
-Param : fZoom: ratio
-Return : true: successfull; false: failed
-Re : here I use m_hOrgBmp as the original bmp, because after zoom in/out
the bmp will distortion
here I create a hSrcDC to show the original bmp, because it have a
infinite size. If we use hDC as the base DC, we may get the wrong
part of the screen!
_Note : This function will set active bmp with orignal bmp, so if you have
changed the active bmp, all the modification will be losed!
-----------------------------------------------------------------------------*/
bool CRobinBMP::ZoomBMP(float fZoom)
{
HDC hDC = GetDC(m_hWnd);
HDC hSrcDC = CreateCompatibleDC(hDC);
HDC hDstDC = CreateCompatibleDC(hDC);
HBITMAP hDstBmp, hOldBmp; int nWidth, nHeight;
BITMAP bmp; if (hDstDC==NULL || hSrcDC==NULL)
return false;
if (GetObject(m_hOrgBmp, sizeof(bmp), &bmp) != 0)
{
nWidth = bmp.bmWidth;
nHeight = bmp.bmHeight; SelectObject(hSrcDC, m_hOrgBmp); // load bmp in src dc hDstBmp = CreateCompatibleBitmap(hDC, nWidth*fZoom, nHeight*fZoom);
hOldBmp = (HBITMAP)SelectObject(hDstDC, hDstBmp); StretchBlt(hDstDC, 0, 0, nWidth*fZoom, nHeight*fZoom, hSrcDC, 0, 0, nWidth, nHeight, SRCCOPY);
// hDstBmp = (HBITMAP)SelectObject(hDstDC, hOldBmp);
hDstBmp = (HBITMAP)GetCurrentObject(hDstDC, OBJ_BITMAP); DeleteObject(hDstDC);
DeleteObject(hSrcDC);
DeleteObject(m_hBmp);
m_hBmp = hDstBmp;
return true;
}
return false;
}