Recent

Author Topic: Resizing an Image and its Contents  (Read 654 times)

Cran0g

  • New Member
  • *
  • Posts: 28
Resizing an Image and its Contents
« on: July 14, 2024, 12:36:03 pm »
Hi everyone,

I've picked up Lazarus from time to time and been distracted by the bling of other languages but I've finally realised that this is where I should be spending my time now that I have a project to concentrate on.

I did a lot of work with RapidQ, a language built on Delphi (so, not a million miles away from Lazarus) and, to an extent, I've been spoiled by it.

So I have to ask a beginner's question which may seem really dumb:

How do you resize a TImage component, in code, so that not only the control changes bounds but the image inside resizes to fill the new boundsl?


I have a banner image I want at the top of the screen.  To ensure it resizes no matter what the client width of the parent form, I'm using an onShow handler for the form in which I set the width of the image to the client width of the form.  The image control width does change but I cannot get the actual picture content to fill it.  It stubbornly sits at 0,0 in its original size when I know that the control has resized.

I've tried every combination I can think of in the object inspector to make the content stretch, but no deal.

Can someone give me a hint?  It's hugely frustrating.   >:D

Thanks in advance.

TRon

  • Hero Member
  • *****
  • Posts: 3618
Re: Resizing an Image and its Contents
« Reply #1 on: July 14, 2024, 12:43:28 pm »
When you use the object inspector when your image component is selected did you perhaps notice the properties of the TImage component such as , let's say, stretch, proportional, stretchinenabled, stretchoutenabled etc ?

If you select such a property the description in the object inspector will be displayed (can also be read here) and most probably tells what you (c/s)hould use for your specific wishes. Note that the ancestors of TImage also provide properties (can been seen in the object inspector) to for example autosize a component.


How do you resize a TImage component, in code, so that not only the control changes bounds but the image inside resizes to fill the new boundsl?

From the provided description of only being necessary to stretch the picture, not a single line of code is required. Just setting (minimal) 2 properties: stretch and align see pictures. If you want the picture to stay in view then setting a sizeconstraint for the height might be helpful as well.

« Last Edit: July 14, 2024, 12:59:19 pm by TRon »
This tagline is powered by AI

Cran0g

  • New Member
  • *
  • Posts: 28
Re: Resizing an Image and its Contents
« Reply #2 on: July 14, 2024, 12:58:23 pm »
Hi TRon,

As I said in my post I've tried all of these.  However, I've now solved it.  I had "Proportional" selected.  I thought that would be correct but it prevents the "Stretch", "StretchInEnabled" and "StretchOutEnabled" from doing what I thought they were there for.

Got it now.

TRon

  • Hero Member
  • *****
  • Posts: 3618
Re: Resizing an Image and its Contents
« Reply #3 on: July 14, 2024, 01:04:22 pm »
...
 I had "Proportional" selected.  I thought that would be correct but it prevents the "Stretch", "StretchInEnabled" and "StretchOutEnabled" from doing what I thought they were there for.
Indeed stretching works a bit counterintuitive when the proportional property is also selected.

Glad to hear that you got it sorted out. thank you for reporting back.
This tagline is powered by AI

 

TinyPortal © 2005-2018