Link to home
Start Free TrialLog in
Avatar of fibdev
fibdev

asked on

Resize image with mousehandler

Hello,

I want to place a bounding box around an image and resize it.  I would like to put points on the corners to resize with preserved aspect ratio.  Thanks in advance.

-Gabe
Avatar of msa2003
msa2003

Maybe, there is something what you need: http://www.serge.dsip.net/downloads/ResizeImage.zip

This sample (Delphi 6) lets user modify image size and aspect ratio by dragging the points in the corners of the image. I had written this specially for you.

Best regards.
Avatar of fibdev

ASKER

msa2003,

It doesn't compile.  I have Delphi 5 Standard :(  Can't afford to go all the way at this time.
Ok, I'll tell when I'll remake it for Delphi 5. You still can use *.pas source.
Or, you may try to remove all files in the project directory except *.dpr, *.dfm and *.pas and compile the project in this state. If the compiler will return errors, place them here.
ASKER CERTIFIED SOLUTION
Avatar of msa2003
msa2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fibdev

ASKER

Thank you msa,

That will do.  It does flicker and I was wondering if there was a way to prevent that.  I'm going to go ahead and give you the comment as answer but if you want to fallow up I'd appreciate it.

Thanks
It does flicker because of usage of TImage component and Repaint method. You may decrease flicker effect but the program will be much more complex.
Avatar of fibdev

ASKER

Thanks
No thanks. It is really complex to avoid flicker. The good way is to use double buffering. But as I noted before, this way is complex enough. You should use a memory bitmap (TBitmap is good for it) and paint stretched image on it's canvas (TBitmap.Canvas.StretchDraw). Then, you should paint this bitmap on the form's canvas (TForm.Canvas.Draw). This way doesn't let you use visual components such as TImage to represent pictures.
Another way is simpler and used by early versions of Windows GUI. You may drag the contour of the image and paint the image only when mouse button is released. Use Form.Canvas.FrameRect to draw, repaint and to hide contour.