求助,绘画一个局部界面放大的问题
上图显示的是下图中实线小方块内的图形, 小方块可移动、可缩放,只要求上图显示小方块内的内容即可 MFC 界面 C++
[解决办法]
很难看,所有的东西一起放大,线都将变得很粗,文本变得很胖
[解决办法]
最近刚做了一个局部放大功能仅供参考!
1.第一种方法 用的是拷贝指定的区域 在另一个指定区域绘制
2.第二种方法 我绘制用了 GID+ DrawImage 实现的
都写在Ondraw的
::DrawPartZomm(Gdiplus::Graphics& graphics,CPoint point ,BOOL bDraw)
{
if( FALSE== bDraw
[解决办法]
m_mouseStat != MS_ZOOM)
return;
int nSqrLen= 40; // 选取区域的长度
CRect rc;
GetClientRect(&rc);
if(!rc.PtInRect(point))
return;
int maxx = rc.right;
int maxy = rc.bottom;
int sourcex = point.x+20;
int sourcey = point.y+20 ;
if(sourcex < 0)
sourcex = 0;
if(sourcex > maxx)
sourcex = maxx;
if(sourcey < 0)
sourcey = 0;
if(sourcey > maxy)
sourcey = maxy;
int windowx = sourcex ;
int windowy = sourcey ;
maxx = rc.right - nSqrLen * 4;
maxy = rc.bottom - nSqrLen * 4;
if(windowx > maxx)
{
windowx = maxx;
if(windowy > maxy)
windowy = sourcey - nSqrLen*4;
}
if(windowy > maxy)
windowy = maxy;
Gdiplus::Rect Desrect(windowx,windowy,160,160);
graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBilinear);
Gdiplus::SolidBrush bgBrush(m_bgColor);
graphics.FillRectangle(&bgBrush, windowx, windowy, 160,160);
graphics.DrawImage(m_image,Desrect,(point.x-offset.X)/zoom-20/zoom,(point.y-offset.Y)/zoom - 20/zoom,nSqrLen/zoom,nSqrLen/zoom,UnitPixel);
Gdiplus::Pen pen(Gdiplus::Color(255,255-m_bgColor.GetR(),255-m_bgColor.GetG(),255-m_bgColor.GetB()));
graphics.DrawRectangle(&pen,windowx -1,windowy -1,162,162);
[解决办法]
也可以截取放大的区域 获得图像信息截屏代码
HBITMAP Cxxxx::CopyScreenToBitmap(LPRECT lpRect)
{
HDC hScrDC, hMemDC;
HBITMAP hBitmap, hOldBitmap;
int nX, nY, nX2, nY2;
int nWidth, nHeight;
CRect rect(lpRect);
LONG lTemp = 0;
if (lpRect->top > lpRect->bottom)
{
lTemp = rect.top;
rect.top = rect.bottom;
rect.bottom = lTemp;
}
if (lpRect->left > lpRect->right )
{
lTemp = rect.right;
rect.right = rect.left;
rect.left = lTemp;
}
if (IsRectEmpty(&rect))
{
TRACE("11111111111");
return NULL;
}
//为屏幕创建设备描述表
hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
//为屏幕设备描述表创建兼容的内存设备描述表
hMemDC = CreateCompatibleDC(hScrDC);
// 获得选定区域坐标
nX = rect.left;
nY = rect.top;
nX2 = rect.right;
nY2 = rect.bottom;
//确保选定区域是可见的
if (nX < 0)
nX = 0;
if (nY < 0)
nY = 0;
int xScreen, yScreen;
xScreen = GetDeviceCaps(hScrDC, HORZRES);
yScreen = GetDeviceCaps(hScrDC, VERTRES);
if (nX2 > xScreen)
nX2 = xScreen;
if (nY2 > yScreen)
nY2 = yScreen;
nWidth = nX2 - nX;
nHeight = nY2 - nY;
// 创建一个与屏幕设备描述表兼容的位图
hBitmap = CreateCompatibleBitmap
(hScrDC, nWidth, nHeight);
// 把新位图选到内存设备描述表中
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
// 把屏幕设备描述表拷贝到内存设备描述表中
BitBlt(hMemDC, 0, 0, nWidth, nHeight,
hScrDC, nX, nY, SRCCOPY);
hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);
//得到屏幕位图的句柄
DeleteDC(hScrDC);
DeleteDC(hMemDC);
// 返回位图句柄
return hBitmap;
}