Solved

# Border size around proportional images

Posted on 2004-11-04
634 Views
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

0
Question by:hyperreal

LVL 26

Expert Comment

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 Comment

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

LVL 26

Expert Comment

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 Comment

Russell,

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

Matt
0

LVL 3

Expert Comment

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

Expert Comment

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 Comment

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

Accepted Solution

PAQed with points refunded (500)

PAQ_Man
Community Support Moderator
0

## Featured Post

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…