Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

images displacement

Status
Not open for further replies.

nanin

Programmer
Aug 29, 2003
13
ES
I'm designing an application in which a user can move a image when he holds down the mouse's left button. The fact is that I need to keep image visible during the operation and, at same time, move the image. I have used OnkeyUp & OnKeyDown events of the image to start this action and OnMouseMove to redraw the image at the new position. The problem is that the image is continuosly redrawing and its appearance isn't too nice. It would be perfect a similar effect like Photoshop or Acrobat pictures/documents displacement.

thank you in advance!
 
You'll want to derive a new component with a Canvas, most likely you'll want to use a TGraphicControl. Make the component cover the entire work area. When the use clicks on a spot on the work area, only a small portion of the component is changed. Use back-buffering to prevent flicker and tearing. Basically your new component's Paint method will look like (in psuedocode):

BackBuffer->Canvas->Clear(...);
BackBuffer->Canvas->Draw(...);
BackBuffer->Canvas->DrawAgainIfNeeded(...);
...

Canvas->Draw(0, 0, BackBuffer->Canvas);

Keep in mind that the Backbuffer's canvas is the same size as Canvas. You will clear the backbuffer's canvas every time, or the data you drew to it previously will still be displayed. Backbuffer needs to be initiated at startup to be most effecient.

Good luck,
Chris
 
I think there is a easier way to solve the problem:

-set container property "DoubleBuffered" to true.
 
That is interesting, I've never noticed that property before. So how does it know when you are done preparing to display the final image? Does it call the PaintWindow method once you return from the Paint method? That would be great knowledge for me, thanks for bringing it up. :)

Chris
 
Oh, one other thing. The DoubleBuffered property is for TWinControl, which TImage is not based on. So you would have to use some other form of Image control based on TWinControl to utilize it I believe.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top