muis2002
asked on
Scaling rectangle
Hi,
I drew a rectangle in a TImage object.
The size of TImage is for example width = W and Height = H.
The rectangle has 4 coordinate positions, X1, Y1, X2, Y2.
Then, I proportionally shrink the TImage to be this size: width = W1 and Height = H1.
So, anyone know a formula to calculate the new X1, Y1, X2, and Y2, so the rectangle will still be proportional ?
Thanks
I drew a rectangle in a TImage object.
The size of TImage is for example width = W and Height = H.
The rectangle has 4 coordinate positions, X1, Y1, X2, Y2.
Then, I proportionally shrink the TImage to be this size: width = W1 and Height = H1.
So, anyone know a formula to calculate the new X1, Y1, X2, and Y2, so the rectangle will still be proportional ?
Thanks
x := X*W1 div W;
x1 := X1*W1 div W;
y := y*H1 div H;
y1 := y1*H1 div H;
F68 ;-)
x1 := X1*W1 div W;
y := y*H1 div H;
y1 := y1*H1 div H;
F68 ;-)
this time you're the faster meikl :))
i'm not sure, if my calculation is correct, f68 :-)
infact looking better in your calculation y must depend on Width scaling factor, that could be different from the height one...
SO
WSCalingFactor := NewWIdth/OldWIdth;
HSCalingFactor := NewHeight/OldHeight;
x1 := x1*WSCalingFactor;
x2 := x2*WScalingFactor;
y1 := y1*HSCalingFactor;
y2 := y2*HScalingFactor;
F68 ;-)
SO
WSCalingFactor := NewWIdth/OldWIdth;
HSCalingFactor := NewHeight/OldHeight;
x1 := x1*WSCalingFactor;
x2 := x2*WScalingFactor;
y1 := y1*HSCalingFactor;
y2 := y2*HScalingFactor;
F68 ;-)
ops...NewWIdth div OldWIdth...etc. etc. (result must be integer, not real)
>ops...NewWIdth div OldWIdth...etc. etc. (result must be integer, not real)
just use round or trunc
>WSCalingFactor := NewWIdth/OldWIdth;
>HSCalingFactor := NewHeight/OldHeight;
i decided to use one scalingfactor, because
if the image is scaled proportional, then
WSCalingFactor and HSCalingFactor
should have the same value
meikl ;-)
just use round or trunc
>WSCalingFactor := NewWIdth/OldWIdth;
>HSCalingFactor := NewHeight/OldHeight;
i decided to use one scalingfactor, because
if the image is scaled proportional, then
WSCalingFactor and HSCalingFactor
should have the same value
meikl ;-)
ASKER
Well, after I tried, it does not works :( not because the calculation, but because of the way TImage stretching :(
I cant get the W1 and H1 (width and height after stretched proportionally).
Original TImage size W * H
then I have newTImage with "smaller" size (let say Wx and Hx).
I assigned TImage to the newTImage, so that newTImage contains TImage bitmap.
But then, I cant get the stretched image size in newTImage.
I checked newTImage.Width , it will always Wx
I checked newTImage.Picture.Width, it will always W (the same with TImage.Width).
I cant get the W1 and H1 (width and height after stretched proportionally).
Original TImage size W * H
then I have newTImage with "smaller" size (let say Wx and Hx).
I assigned TImage to the newTImage, so that newTImage contains TImage bitmap.
But then, I cant get the stretched image size in newTImage.
I checked newTImage.Width , it will always Wx
I checked newTImage.Picture.Width, it will always W (the same with TImage.Width).
the picture width never changes,
only the visualizing of the TImage
is adjusted (autostretch-property is set to true)
if you want the picture scaled physically,
then use canvas-methods like
- Stretchdraw
- copyrect
or api like
- BitBlt
to create a new scaled picture
meikl ;-)
only the visualizing of the TImage
is adjusted (autostretch-property is set to true)
if you want the picture scaled physically,
then use canvas-methods like
- Stretchdraw
- copyrect
or api like
- BitBlt
to create a new scaled picture
meikl ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
scalingfactor := NewHeight/OldHeight;
newX1 := x1*scalingfactor;
newY1 := y1*scalingfactor;
newX2 := y2*scalingfactor;
newY2 := y2*scalingfactor;
meikl ;-)