Recent

Author Topic: [SOLVED] Creating grayscaled icons using BGRABitmap  (Read 2601 times)

Wargan

  • New Member
  • *
  • Posts: 48
    • 'This way' site
[SOLVED] Creating grayscaled icons using BGRABitmap
« on: August 18, 2017, 03:01:48 pm »
Hello!
I'm using SpkToolbar (an advanced toolbar similar to Office2007) in my project.
Unfortunately, SpkToolbar can not automatically create "grayed" icons for disabled buttons.
How can I create a GrayedIconsList (TBGRAImageList) "on the fly" using the capabilities of BGRABitmap?
I have SpkIconsList (32x32) icons on my Form.
« Last Edit: September 09, 2017, 09:07:13 am by Wargan »
Lazarus 1.8RC5+ FPC 3.0.4.
Windows 7 x32, RAM 3 Gb.

lainz

  • Hero Member
  • *****
  • Posts: 4470
    • https://lainz.github.io/
Re: Creating grayscaled icons using BGRABitmap
« Reply #1 on: August 18, 2017, 05:28:33 pm »
Hello!
I'm using SpkToolbar (an advanced toolbar similar to Office2007) in my project.
Unfortunately, SpkToolbar can not automatically create "grayed" icons for disabled buttons.
How can I create a GrayedIconsList (TBGRAImageList) "on the fly" using the capabilities of BGRABitmap?
I have SpkIconsList (32x32) icons on my Form.

Here you go, works with ImageList and BGRAImageList. ImageList1 is your SkpIconsList, ImageList2 is your GrayedIconsList. BTW I've not tested it with Alpha blended images...

Code: Pascal  [Select][+][-]
  1. uses
  2. GraphType...
  3.  
  4. ...
  5.  
  6. procedure TForm1.FormCreate(Sender: TObject);
  7. var
  8.   i: integer;
  9.   temp: TBitmap;
  10. begin
  11.   ImageList2.Width:= ImageList1.Width;
  12.   ImageList2.Height:= ImageList1.Height;
  13.   for i:=0 to ImageList1.Count-1 do
  14.   begin
  15.     temp := TBitmap.Create;
  16.     ImageList1.GetBitmap(i, temp, gdeDisabled);
  17.     ImageList2.Add(temp, nil);
  18.     temp.Free;
  19.   end;
  20.  
  21. // change when needed
  22.   BCButton1.Images := ImageList2;
  23.   BCButton1.ImageIndex := 0;
  24. end;

Wargan

  • New Member
  • *
  • Posts: 48
    • 'This way' site
Re: Creating grayscaled icons using BGRABitmap
« Reply #2 on: August 20, 2017, 10:28:13 am »
Hello, lainz!
Your code works fine, but only missing Graphics in the uses section  :)

One more question: it's possible to make the icons not only "grayed", but also transparent, for example opacity=50%?
Lazarus 1.8RC5+ FPC 3.0.4.
Windows 7 x32, RAM 3 Gb.

lainz

  • Hero Member
  • *****
  • Posts: 4470
    • https://lainz.github.io/
Re: Creating grayscaled icons using BGRABitmap
« Reply #3 on: August 20, 2017, 08:19:31 pm »
Usually Graphics is included in a fresh form.

To make them transparent, instead of creating a TBitmap create a TBGRABitmap, draw the icon on it, then apply the global opacity you need, and finally save it in the image list, maybe is possible with the BGRABitmap.Bitmap property. If not, you need to draw it to a TBitmap first.

 

TinyPortal © 2005-2018