放大图片控件. [英] Zooming in picture control.

查看:69
本文介绍了放大图片控件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个基于 dialog 的应用程序,用于绘制图形.

在其中,它具有一个Picture控件,该控件已作为静态类派生,并且使用GDI +进行绘制.

我已经在鼠标事件中处理了橡皮筋矩形.
但是,如何使用橡皮筋矩形放大/缩小?
我发现了一个名为strechblt的函数,但是放大时,图形将被拉伸和模糊.无论如何,我可以重画图片控件中橡皮筋矩形内的内容吗?

我发现的所有示例都使用Cwnd或CScrollView.

这就是我处理鼠标事件以及绘制矩形的方式.

Hi,

I have a dialog based application which is used to plot graphs.

And in it, it has a Picture control which I have derived as a Static Class, and I''m using GDI+ to draw.

I''ve already handle the rubber-banding rectangle in the mouse events.
But how do i zoom in/out using the rubber-band rectangle?
I''ve found a function called strechblt, but when zooming in, the graphs will be strectched and blurred. Is there anyway that i can redraw what is inside the rubber-band rectangle in the picture control?

All the examples i found were using Cwnd or CScrollView.

This is how i handle my mouse events and how i draw the rect.

void CGraph::OnLButtonDown(UINT nFlags, CPoint point)
{
	CGraphicPlotter1Dlg *dlg = (CGraphicPlotter1Dlg*) this->GetParent();
	this->GetWindowRect(rcPic);
	this->ScreenToClient(rcPic);
	CPoint curPoint;
	GetCursorPos(&curPoint);
	mousePt.x = curPoint.x;
	mousePt.y = curPoint.y;
	if(rcPic.PtInRect(mousePt))
	{
		m_Track = TRUE;
		m_ptStart = point;
		m_ptEnd  = point;
		SetCapture();
	}
	InvalidateRect(rcPic,FALSE);
	CStatic::OnLButtonDown(nFlags, point);
}

void CGraph::OnLButtonUp(UINT nFlags, CPoint point)
{
	m_Track = FALSE;
	InvalidateRect(rcPic,FALSE);
	GetClientRect(rcMouse);
	rcMouse.NormalizeRect();
	if (GetCapture() == this && rcPic.BottomRight().x >= rcMouse.BottomRight().x 
							 && rcPic.BottomRight().y >= rcMouse.BottomRight().y)
	{	
		ReleaseCapture();
		m_ptEnd = point;
	}
	ReleaseCapture();
	CStatic::OnLButtonUp(nFlags, point);
}

void CGraph::OnMouseMove(UINT nFlags, CPoint point)
{
	if (GetCapture() == this && m_Track == TRUE)
	{ 
		m_ptEnd = point;
	}
	InvalidateRect(rcPic,FALSE);
	CStatic::OnMouseMove(nFlags, point);
}



并在onPaint中:



and in onPaint:

if (m_Track == TRUE)
	{
		CRect r(m_ptStart, m_ptEnd);
		float mouseWidth = r.Width();
		float mouseHeight = r.Height();
		RectF rcGdi(r.TopLeft().x, r.TopLeft().y, mouseWidth, mouseHeight);
		g.DrawRectangle(&mousePen, rcGdi);
	}

推荐答案

这不是问题.但是,如果您的问题是您不喜欢放大的图片质量,我可以回答.你能保守秘密吗?那就听:没有奇迹.



对后续讨论的答复.

在这种情况下,它们的图形应该是矢量,而不是位图(像素)图形.

您需要具有逻辑上描述图形的数据模型.模型应具有内容,还应具有缩放或平移等查看参数.您需要根据内容,缩放,平移等动态地渲染模型.

为此,您需要处理某些控件的WM_PAINT事件,用作绘图表面.图形的更改是通过更改数据模型或查看参数并调用Invalidate函数来完成的.

(并且,请不要将您的评论或问题作为解决方案"发布-将被删除;没有人会收到电子邮件通知.相反,请在其他帖子上发表评论,请使用改善问题".)

—SA
This is not a question. However, if your problem is that you don''t like the quality of the picture which you enlarge, I can answer. Can you keep a secret? Listen then: there is no such thing as miracle.



A reply to the follow-up discussion.

They graphics should be vector in this case, never bitmap (pixel) graphics.

You need to have your data model describing the graph logically. The model should have content and also viewing parameters like zoom or pan. You need to render model dynamically depending on the content, zoom, pan, etc.

For this purpose, you need to handle WM_PAINT event of some control, working as the drawing surface. The change in graphic is done via the change of the data model or viewing parameters and calling on of Invalidate functions.

(And please, don''t post your comments or questions as a "solution" — will be removed; no one gets e-mail notification. Instead, comment on other posts, use "Improve question".)

—SA


请遵守以下代码;它可以给您您的下一个想法:):
Please observe the following code; it can give you your next ideas :) :
// Trnsformer.h
  class CDrawTransformer
  {
    /// Context to serve
    CDC*  m_pDC;
    /// ID of the original context
    int   m_iOriginalDC;
    /// Mode of the original context
    int   m_iOriginalMode;
    /// Original matrix
    XFORM m_xOriginalForm;
    /// Working matrix
    XFORM m_xWorkingForm;

  public:
    CDrawTransformer(CDC* pDC, const CRect& crViewCell, int iZoomPercent);
    ~CDrawTransformer();

    void Release();
  };

// Transformer.cpp
CDrawTransformer::CDrawTransformer(CDC* pDC,
                                   const CRect& crViewCell,
                                   int iZoomPercent)
: m_pDC(pDC)
{
  ASSERT(m_pDC->GetSafeHdc());

  m_iOriginalDC = SaveDC(m_pDC->m_hDC);
  m_iOriginalMode = SetGraphicsMode(m_pDC->m_hDC, GM_ADVANCED);
  GetWorldTransform(m_pDC->m_hDC, &m_xOriginalForm);

  float fZoomFactor   = (float) iZoomPercent / 100.0f;
  m_xWorkingForm.eM11 = fZoomFactor;
  m_xWorkingForm.eM12 = 0.0f;
  m_xWorkingForm.eM21 = 0.0f;
  m_xWorkingForm.eM22 = fZoomFactor;
  m_xWorkingForm.eDx  = (float) crViewCell.left;
  m_xWorkingForm.eDy  = (float) crViewCell.top;
  SetWorldTransform(m_pDC->m_hDC, &m_xWorkingForm);
}

CDrawTransformer::~CDrawTransformer()
{
  Release();
}

void CDrawTransformer::Release()
{
  if (m_pDC->GetSafeHdc()) {
    SetWorldTransform(m_pDC->m_hDC, &m_xOriginalForm);
    SetGraphicsMode(m_pDC->m_hDC, m_iOriginalMode);
    RestoreDC(m_pDC->m_hDC, m_iOriginalDC);
    m_pDC = NULL;
  }
}

// YourDraw.cpp
void CYourWnd::SomeDrawing(CDC* pDC,
                           const CRect& crViewCell,
                           int iZoomPercent)
{
  // 1. Construct a transformer
  CDrawTransformer cTransformer(pDC, crViewCell, iZoomPercent);
  // 2. Init your GDI+ graphics
  graphics g(pDC, ...);
  // 3. Draw the cell in (0, 0) origin
  GdiPlusDraw(g, crViewCell.Size());
}

void CYourWnd::GdiPlusDraw(graphics& g, const CSize& sizeCell)
{
  // Please note: you have to draw the cell in the origin(0, 0) here !

  //..
}


这篇关于放大图片控件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆