hyperreal
asked on
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?
Many thanks in advance
Matt Briggs
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?
Many thanks in advance
Matt Briggs
ASKER
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?
Many thanks in advance.
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?
Many thanks in advance.
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
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
ASKER
Russell,
I'm using Delphi 6, and need to know the border sizes around the image when the image is proportional.
Matt
I'm using Delphi 6, and need to know the border sizes around the image when the image is proportional.
Matt
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
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
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
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
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;