Board index » delphi » Working out a cliprect in reverse
Peter Morris [Air Software Ltd]
![]() Delphi Developer |
Working out a cliprect in reverse2005-01-04 06:49:21 AM delphi206 Hi all This is the best I can explain :-) 1) I have an image control which is 100 wide and 100 high 2) The image has a picture which is 100 pixels by 100 pixels 2) I work out how large the picture would be if rotated / scaled like so (Source for GetRotatedSize to follow) Width is 100 Height is 100 Angle = 45 ScaleX / ScaleY = 500 (that's %) var S: TPoint; begin S := GetRotatedSize(Width, Height, Angle, ScaleX, ScaleY); Caption := IntToStr(S.X) + ', ' + IntToStr(S.Y) + ' / ' + FloatToStr(DIBImage1.Scale); end; The result is that the scaled/rotated size is 708 pixels by 708 pixels. Obviously if I centre this scaled / rotated bitmap in my 100x100 image control there would be some clipping. What I want to know is, how do I reverse this process, so that I can work out the clip rect of the original picture? function GetRotatedSize(Width, Height: Word; Angle: Extended; ScaleX, ScaleY: Extended): TPoint; var Radians: Double; ScaleW, ScaleH: Double; begin Assert((Angle>= 0) and (Angle < 360)); Radians := DegToRad(-Angle); ScaleW := Width * ScaleX / 100; ScaleH := Height * ScaleY / 100; Result := Point(Ceil(Abs(ScaleW * Cos(Radians)) + Abs(ScaleH * Sin(Radians))), Ceil(Abs(ScaleW * Sin(Radians)) + Abs(ScaleH * Cos(Radians)))); Result.X := Result.X + (Result.X mod 2); Result.Y := Result.Y + (Result.Y mod 2); end; -- Pete ==== Audio compression components, DIB graphics controls, FastStrings www.droopyeyes.com Read or write articles on just about anything www.HowToDoThings.com My blog blogs.slcdug.org/petermorris/ |