Image smoothing rolling effect VC implementation

zhaozj2021-02-11  217

Image smoothing rolling effect VC implementation Zheng Liqun

Preface:

In the programming of the image, this is often encountered, and a large picture is displayed in a limited area.

At this time, you want to browse the various parts of the image, which requires the scrolling of the image. Regarding its implementation, many books have

It is mentioned, but the key points and difficulties, that is, the refresh and flicker problems in the drag, but there is not much, this is also

I am in writing this article, and I will analyze the implementation method in detail.

Implementation and implementation methods:

Press the left mouse button in the image area to drag the image arbitrarily rolled in a limited area.

The method is: Calculate the offset of the last time, then change the starting point of the image display and brush

New image area.

Implementation part:

The first step: respond to the WM_LBUTTONDOWN message, the record is pressed to start dragging the starting position.

Void cwingimgdlg :: ONLBUTTONDOWN (uint nflags, cpoint point)

{

// Todo: add your message handler code here and / or call default

M_LPicoldLeft = Point.x;

m_lpicoldtop = point.y;

CDIALOG :: ONLBUTTONDOWN (NFLAGS, POINT);

}

Step 2: Respond to the WM_MOUSEMOVE message to implement scrolling.

Void CwingImgdlg :: OnMousemove (uint nflags, cpoint point)

{

// Todo: add your message handler code here and / or call default

If the mouse is pressed

IF ((NFLAGS & MK_LBUTTON) == mk_lbutton)

{

M_LPICNEWLEFT = POINT.X;

M_LPICNEWTOP = POINT.Y;

DWORD DWLRSHIFT = M_LPICNEWLEFT - M_LPICOLDLEFT;

DWORD DWTBSHIFT = M_LPICNEWTOP - M_LPICOLDTOP;

Change the starting point of the image display

M_LPicleft = m_lpicleft - dwlrshift;

M_LPictop = M_LPictop - DWTBSHIFT;

Judgment the statement of the boundary, save.

M_LPicoldLeft = M_LPICNEWLEFT;

M_LPicoldTop = M_LPICNEWTOP;

See the fourth step.

}

CDIALOG :: OnMousemove (NFLAGS, POINT);

}

Step 3: Displayed in onpain, other parts of the display, such as the image of the image, etc., save.

Void cwingimgdlg :: onpaint ()

{

CPAINTDC DC (this); // Device Context for Painting

Other display content, province.

IF (M_Pimginfo! = NULL)

DC.Bitblt (m_wshowadjleft, m_wshowadjtop, m_lwidth, m_lheight, & m_adjdc,

M_LPicleFT, M_LPictop, Srccopy;

CDIALOG :: onpaint ();

}

Step 4: Refresh the process.

The most often thought of, of course, INVALIDATE (TRUE); // Refresh the entire invalid area

UpdateWindow ();

At this time, the invalid zone of the entire program area will be refreshed, the flashes are very serious, and the following: InvalIdateRect (& M_RTPIC, TRUE); only refreshed image display area

UpdateWindow ();

At this time, only the area where the image is refreshed, the flash is alleviated, and then further, can be used

INVALIDATERECT (& M_RTPIC, TRUE); use fast redraw

RedrawWindow (& M_RTPIC, NULL, RDW_INTERNALPAINT |

RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);

Performance, the flashing is further reduced, taken into account, other parts may affect the refresh area, simply

Onpaint () directly here, that is, to:

OnPaint ();

But if there is a lot of drawing statement in OnPaint (), this method is still not feasible, considering can't stimulate

ONPAINT () This factor and control refresh range, I use the following non-standard method to solve, the code is as follows:

CDC * PDC;

PDC = GetDC ();

IF (M_Pimginfo! = NULL)

PDC-> Bitblt (m_wshowleft, m_wshowtop, m_lwidth, m_lheight, & m_adjdc, m_lpicleft, m_

LPictop, Srccopy;

ReleaseDC (PDC);

This approach solves the problem of refreshing and flicker, and the image is very smooth and no flashes.

This is a question I have encountered in practice, written, and share it with you. If there is a problem, or there is more

Good suggestions and practices, welcome to contact me, if you need the source file of the entire program, please contact Mail (

Davidzheng@acercm.com.cn).

转载请注明原文地址:https://www.9cbs.com/read-4522.html

New Post(0)