[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 649
  • Last Modified:

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



0
hyperreal
Asked:
hyperreal
1 Solution
 
Russell LibbySoftware Engineer, Advisory Commented:
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
 
hyperrealAuthor 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?

Many thanks in advance.
0
 
Russell LibbySoftware Engineer, Advisory Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hyperrealAuthor Commented:
Russell,

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

Matt
0
 
gandalf_the_whiteCommented:
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
 
hyperspeed2Commented:
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
 
hyperrealAuthor 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
 
PAQ_ManCommented:
PAQed with points refunded (500)

PAQ_Man
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now