请问怎么用VC++实现图形缩放?

时间:2022-03-21 19:34:34
我现在在用VC++编一个类似windows自带的画图程序,请问怎么实现放大和缩小的功能,要求线条粗细不变,而且可以用鼠标拖动选择要放大的区域。请大虾指点。  

14 个解决方案

#1


StretchBlt可以缩放

#2


可是StretchBlt会使线条变粗啊?

#3


StretchBlt可以,放大就是使线条变粗.描述单个点的像素个数增加,所以会变粗.

#4


可以自己用插点算法写放大函数。

#5


自己写的函数,在OnDraw里调用
void PutViewPort(CDC* pDC)
{
if (m_NewCursorPoint!=m_OldCursorPoint)
{
m_CenterPointX += (long)((double)(m_OldCursorPoint.x-m_NewCursorPoint.x)/(double)m_ZoomScale);
m_CenterPointY += (long)((double)(m_OldCursorPoint.y-m_NewCursorPoint.y)/(double)m_ZoomScale);
m_NewCursorPoint=m_OldCursorPoint;
}

long tpWidth;
long tpHeight;
m_gpPicture->get_Width(&tpWidth);
m_gpPicture->get_Height(&tpHeight);
double pBL=((double)tpWidth)/((double)tpHeight);

RECT rc;
GetClientRect(&rc);

long vWidth=rc.right;
long vHeight=rc.bottom;
double vBL=((double)vWidth)/((double)vHeight);

long tvWidth;
long tvHeight;
if (pBL>vBL)
{
tvWidth=vWidth;
tvHeight=(long)((double)tvWidth/pBL);
}
else
{
tvHeight=vHeight;
tvWidth=(long)((double)tvHeight*pBL);
}

long trueWidth=(long)((double)tvWidth*m_ZoomScale);
long trueHeight=(long)((double)tvHeight*m_ZoomScale);

long trueX=(vWidth-trueWidth)/2-(long)((double)m_CenterPointX*m_ZoomScale);
long trueY=(vHeight-trueHeight)/2-(long)((double)m_CenterPointY*m_ZoomScale);

HDC hdc=pDC->GetSafeHdc(); 
m_gpPicture->Render(hdc,trueX,trueY,trueWidth,trueHeight,0,tpHeight,tpWidth,-tpHeight,&rc);

}

#6


该回复被版主删除

#7


那用坐标变换可以吗?
就是设置窗口,视口的范围可以吗?

#8


to: zy3481(远影孤帆) 

    什么叫插点算法

#9


晕,补补“计算机数学基础”吧!

#10


设置坐标的映射模式就可以了
不会改变线条粗细

#11


插点算法
<<数字图象处理>>  冈萨雷斯

#12


这个是图像放大
看看 何斌的<数字图像编程>

#13


我有这方面的代码,要不要咯?
给点分就行了

#14


mark

#1


StretchBlt可以缩放

#2


可是StretchBlt会使线条变粗啊?

#3


StretchBlt可以,放大就是使线条变粗.描述单个点的像素个数增加,所以会变粗.

#4


可以自己用插点算法写放大函数。

#5


自己写的函数,在OnDraw里调用
void PutViewPort(CDC* pDC)
{
if (m_NewCursorPoint!=m_OldCursorPoint)
{
m_CenterPointX += (long)((double)(m_OldCursorPoint.x-m_NewCursorPoint.x)/(double)m_ZoomScale);
m_CenterPointY += (long)((double)(m_OldCursorPoint.y-m_NewCursorPoint.y)/(double)m_ZoomScale);
m_NewCursorPoint=m_OldCursorPoint;
}

long tpWidth;
long tpHeight;
m_gpPicture->get_Width(&tpWidth);
m_gpPicture->get_Height(&tpHeight);
double pBL=((double)tpWidth)/((double)tpHeight);

RECT rc;
GetClientRect(&rc);

long vWidth=rc.right;
long vHeight=rc.bottom;
double vBL=((double)vWidth)/((double)vHeight);

long tvWidth;
long tvHeight;
if (pBL>vBL)
{
tvWidth=vWidth;
tvHeight=(long)((double)tvWidth/pBL);
}
else
{
tvHeight=vHeight;
tvWidth=(long)((double)tvHeight*pBL);
}

long trueWidth=(long)((double)tvWidth*m_ZoomScale);
long trueHeight=(long)((double)tvHeight*m_ZoomScale);

long trueX=(vWidth-trueWidth)/2-(long)((double)m_CenterPointX*m_ZoomScale);
long trueY=(vHeight-trueHeight)/2-(long)((double)m_CenterPointY*m_ZoomScale);

HDC hdc=pDC->GetSafeHdc(); 
m_gpPicture->Render(hdc,trueX,trueY,trueWidth,trueHeight,0,tpHeight,tpWidth,-tpHeight,&rc);

}

#6


该回复被版主删除

#7


那用坐标变换可以吗?
就是设置窗口,视口的范围可以吗?

#8


to: zy3481(远影孤帆) 

    什么叫插点算法

#9


晕,补补“计算机数学基础”吧!

#10


设置坐标的映射模式就可以了
不会改变线条粗细

#11


插点算法
<<数字图象处理>>  冈萨雷斯

#12


这个是图像放大
看看 何斌的<数字图像编程>

#13


我有这方面的代码,要不要咯?
给点分就行了

#14


mark