0

Probably pretty simple but I was trying to figure out how to get an Image to fill a TRoundRect in Delphi FMX. I've got a roundrect on my form, got an image assigned to it but when I load a rectangle shaped bitmap into the image it displays in its usual width/height ratio so overlays the roundrect which sits underneath it. The relevant bit of my code looks like this:

Rec := TRoundRect.Create(Self);
Rec.Height := 180;
Rec.Width := 250;
Rec.Corners := [TCorner.TopLeft, TCorner.TopRight, TCorner.BottomLeft];

Image := TImage.Create(Self);
Image.Parent := Rec;
Image.Bitmap := TBitmap.Create;
Image.Align := TAlignLayout.Client;
Image.WrapMode := TImageWrapMode.Stretch;
Image.Bitmap.LoadFromFile('C:\temp\test.bmp');
Image.Bitmap := FAllProgrammes[I].Image;

FlowLayout1.AddObject(Rec);

Does anyone have any suggestions/pointers on how I can clip the image to fit and fill out the TRoundRect either through using some property of the parent or the TRoundRect canvas? Cheers

Fabrizio
  • 7,603
  • 6
  • 44
  • 104

1 Answers1

2

Thanks to John for the pointer. That in conjunction with this demo i tracked down on the Embarcadero website managed to get me the answer. Just in a quick standalone project i dropped a roundrect onto the form and a button. Then behind a button click add some code to create a bitmap then assign it to the roundrect:

procedure TForm2.Button1Click(Sender: TObject);
var
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create;
  Bitmap.LoadFromFile('C:\temp\test.jpg');
  RoundRect1.Fill.Kind := TbrushKind.Bitmap;
  RoundRect1.Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
  RoundRect1.Fill.Bitmap.Bitmap := Bitmap;
end;
  • 1
    Why are you creating TImage component (visible component) just so that you can load some image file into it and then pass its Bitmap as parameter to RoundRect.Fill method. It would be better if you would go and create TBitmap instead and then pass it as parameter to RoundRect.Fill method – SilverWarior Jul 23 '18 at 20:00
  • As @SilverWarior says, you don't need to create a TImage just to pass a bitmap. Your self-answer would be more useful if you change it. – Dave Nottage Jul 23 '18 at 20:23
  • Cheers for the pointer there. Still pretty early days in my delphi understanding so appreciate the help. – Alexander James Jul 24 '18 at 14:58