Recent

Author Topic: TCustomImageList.InsertMasked does not support multiple insertion in Lazarus 2.0  (Read 72 times)

Dmitry24

  • New Member
  • *
  • Posts: 13
In Lazarus 2.X TCustomImageList.InsertMasked now inserts a single image only by scaling entire Bitmap to a single icon.

lcl/include/imglist.inc:
Code: Pascal  [Select]
  1. procedure TCustomImageList.InsertMasked(Index: Integer; AImage: TCustomBitmap;
  2.   MaskColor: TColor);
  3. var
  4.   MaskedImage: TBitmap;
  5.   ScBmp: TRGBAQuadArray;
  6.   R: TCustomImageListResolution;
  7. begin
  8.   if AImage = nil then Exit;
  9.  
  10.   MaskedImage := TBitmap.Create;
  11.   try
  12.     MaskedImage.Assign(AImage);
  13.     MaskedImage.TransparentColor := MaskColor;
  14.     MaskedImage.TransparentMode := tmFixed;
  15.     MaskedImage.Transparent := True;
  16.  
  17.     CreateDefaultResolution;
  18.     for R in Resolutions do
  19.     begin
  20.       ScaleImage(MaskedImage.BitmapHandle, MaskedImage.MaskHandle, Rect(0, 0, MaskedImage.Width, MaskedImage.Height), R.Width, R.Height, ScBmp);
  21.       R.InternalInsert(Index, @ScBmp[0]);
  22.     end;
  23.   finally
  24.     MaskedImage.Free;
  25.   end;
  26. end;  
  27.  

Previously in Lazarus 1.X multiple bitmaps were inserted basing on the bitmap width (bitmap width / imagelist width). Currently there is AddSliced function which allows multiple insertion but it does not support Index and a MaskColor.

Is this a bug or feature? Is there a simple way to return the previous behaviour? Or we have to use helpers to access private functions (CreateDefaultResolution, InternalInsert)?

P.S. Using a temporary masked bitmap resolves MaskColor applying. However Index support requires more effort.
« Last Edit: September 09, 2019, 07:24:03 pm by Dmitry24 »