Search code examples
imagelistviewbitmapgeometryfiremonkey

Firemonkey - how to place an Tlistitemimage in a circle


I have a listview with an images and data in each item. I want my image (which is a TlistitemImage to look like the below.

image

I can do this very easily by using Tcircle and using mycircle.fill.bitmap.bitmap, eg code below lcircle.fill.Bitmap.Bitmap.LoadFromFile(TPath.GetDocumentsPath + PathDelim + 'test.png'); however i simply cannot create a circle for each listitem :-(

The other option i have is to use Tlistitemimage - code below:

  LImage := TListItemImage.Create(mylistviewitem);
       LImage.Name := 'image';
       LImage.Align := TListItemAlign.Leading; // En Sað
       LImage.VertAlign := TListItemAlign.center; // Orta
       LImage.PlaceOffset.Y := 0;
       LImage.PlaceOffset.X := 0;
       Limage.width := 80;
       LImage.Height := 80;

       LImage.OwnsBitmap := True;
       LImage.Bitmap := TBitmap.Create(0,0);

Limage.Bitmap.LoadFromFile(TPath.GetDocumentsPath + PathDelim + 'test.png');

Now the idea i had was to then create the Tcircle and make the parent of the circle the TListItemImage. That unfortunately does not work :-(

I have also tried doing this with the stylebook, creating a new style called listitemimagestyle and creating a tcircle within that style but that also does nothing.

Can someone please assist me?

Thank you - and yes, i am a noobie so be nice


Solution

  • I'd use TBitmap.CreateFromBitmapAndMask in order to create your bitmap using a mask. The mask would be a black&white image that contains your circle.