Border size around proportional images

Hi there!

I'd be really grateful if someone could help me out with this problem I have.

I'm using the TImage component within Delphi to display images, and have set it to display images proportionally. How is it possible to calculate or get the image compoent to return the size of the left/right/top/bottom borders around the picture?

Matt Briggs

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Matt,
The following is from the calculations used by the Paint procedure in TImage. This will let you get both the Rect for the control as well as the image.

Hope this helps,
Russell

// Assuming a control called Image1
var  rcImage:    TRect;
rcCtl:      TRect;
begin

// Get the control rectangle
rcCtl:=Rect(0, 0, Image1.Width, Image1.Height);

// Get the actual image rect
with Image1 do
begin
if Stretch then
rcImage:=rcCtl
else if Center then
rcImage:=Bounds((Width - Picture.Width) div 2, (Height - Picture.Height) div 2, Picture.Width, Picture.Height)
else
rcImage:=Rect(0, 0, Picture.Width, Picture.Height);
end;

// Do whatever with the rects

end;

0
Author Commented:
Russell,

The picture displayed within Image1 is Streched, Centred and Proportional. As a result the above code does not seem to give me the left, right and top,bottom border size around the image.

var
leftBorder: integer;
rightBorder: integer;
topBorder: integer;
bottomBorder: integer;

begin
Image1.AutoSize := True;
Image1.Centre := True;
Image1.Proportional := True;
Image1.Picture := 'c:\test.bmp';

. . .
leftBorder := rcImage.Left;
bottomBorder := rcImage.Bottom;
. . .

... Any thoughts?

0
Matt,

What version of delphi are you working with? Looking at D5, there is no "Proportional" setting, just the strecth and center; in which case the stretch overrides the center value (and the image is stretched to the dimensions of the control, leaving no border).

Russell
0
Author Commented:
Russell,

I'm using Delphi 6, and need to know the border sizes around the image when the image is proportional.

Matt
0
Commented:
i think you want to have the information what the stretch property of the timage has done.

for this you should load the image with autosize := true and  proportional and stretch  := false;
now you know how big the original is.
if you save these values and compare them to the proportional := true image you should
know how big your border is.

regards
alfred
0
Commented:
Apologies, DanRollins.

Unfortunetly, no one managed to supply the answer I was looking for, and I managed to figure it out by calculating the image scaling myself. I'll post the code I used on here shortly.

Many thanks to all that attempted to help.

View the image scaling in action:
http://web.ukonline.co.uk/mattbriggs
0
Author Commented:
OK,

As promised, here is the code I used:

---

Ratio := imgsolution.picture.Width / imgsolution.picture.Height;
AWidth := Round(image1.Height * Ratio);
AHeight := Round(image1.Width / Ratio);
lborder := (round((image1.Width - AWidth) / 2));
tborder := (round((image1.Height - AHeight) / 2));
if (lborder < 0) then
lborder:=0;
if (tborder < 0) then
tborder:=0;

---

Play Matt's 15-1 Puzzle Game:
http://web.ukonline.co.uk/mattbriggs
0
Commented:
PAQed with points refunded (500)

PAQ_Man
Community Support Moderator
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.