问题描述
我将我的代码从vb转换为c ++有一些动态点可以绘制不同的形状。
在vb中它们具有.ScaleWidth等属性,.ScaleHeight,.ScaleTop,.ScaleLeft。
他们所做的是他们根据宽度和高度使用这些属性缩放并绘制点(形状) vb中的图片框。
但在mfc我有所需的所有输入点但是当iam绘图无法正确或正确绘制。请帮帮我,即无法正确伸缩,请帮帮我。
我尝试过:
i am converting my code from vb to c++ there are some dynamic points which are there to draw different shapes.
in vb they have properties such as .ScaleWidth, .ScaleHeight, .ScaleTop , .ScaleLeft.
what they had done is they had scaled according to width and height using these properties and draw points(shapes) on the picture box in vb.
but in mfc i have all the input points required but when iam drawing not able to draw properly or correctly. please help me i.e not able to scale properly please help me out.
What I have tried:
void CPDlgToolPreview::S_SetDrawingScale()
{
short i;
float lnMaxX;
float lnMaxY;
float lnMinX;
float lnMinY;
const int BigNumber = 1000000000;
float lnWidth;
float lnHeight;
lnMaxX = (float)(-BigNumber);
lnMaxY = (float)(-BigNumber);
lnMinX = (float)(BigNumber);
lnMinY = (float)(BigNumber);
for (i = 0; i < mlPoints; i++)
{
if (moPts[i].X > lnMaxX) lnMaxX = (float)(moPts[i].X);
if (moPts[i].Y > lnMaxY) lnMaxY = (float)(moPts[i].Y);
if (moPts[i].X < lnMinX) lnMinX = (float)(moPts[i].X);
if (moPts[i].Y < lnMinY) lnMinY = (float)(moPts[i].Y);
}
lnWidth = lnMaxX - lnMinX;
lnHeight = lnMaxY - lnMinY;
CRect cRect;
m_cPreview.GetClientRect(&cRect);
if ( lnWidth / cRect.Width() > lnHeight / cRect.Height() )
{
// Scale according to items width
nScaleWidth = lnWidth*1.2;
nScaleHeight = cRect.Height() *nScaleWidth / cRect.Width();
}
else
{
// Scale according to items height
nScaleHeight = lnHeight*1.2;
nScaleWidth = cRect.Width() *nScaleHeight / cRect.Height();
}
nScaleleft = -nScaleWidth / 2;
nScaletop = -((nScaleHeight - lnHeight) / 2) - lnHeight;
}
for (short i = 2; i < mlPoints; i++)
{
DrawLine(m_cPreview, moPts[i].X , moPts[i].Y);
}
void DrawLine(CWnd * wnd,int x1,int y1,int x2,int y2,int rgb)
{
CDC * cdc = wnd-> GetDC();
CPen * oldPen = cdc-> SelectObject(新CPen( 0,3,rgb));
cdc-> MoveTo(x1,y1);
cdc-> LineTo(nCurrentx = x2,currenty = y2);
删除(CPen *)cdc-> SelectObject(oldPen);
wnd-> ReleaseDC(cdc);
}
在哪里使用这些scaleleft,nScaleHeight等来获得正确的形状。
void DrawLine(CWnd *wnd, int x1, int y1, int x2, int y2, int rgb)
{
CDC *cdc = wnd->GetDC();
CPen *oldPen = cdc->SelectObject(new CPen(0, 3, rgb));
cdc->MoveTo(x1, y1);
cdc->LineTo(nCurrentx = x2, currenty= y2);
delete (CPen *)cdc->SelectObject(oldPen);
wnd->ReleaseDC(cdc);
}
where to use these scaleleft, nScaleHeight etc to get proper shape.
推荐答案
这篇关于绘图所有者绘制图片控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!