Recent

Author Topic: Save Icon Form ImageList  (Read 3802 times)

BenJones

  • Full Member
  • ***
  • Posts: 121
Save Icon Form ImageList
« on: May 08, 2013, 09:10:03 am »
Hi I am trying to save a icon from the Imagelist control, I managed to load my bitmap in and save it as a icon, but the only problum it saveing as a default XP color depth, is there any way to set the color depth of the image list here my code I have for saving.
I like to save as maybe a 16 color icon or 256 color.

Code: [Select]
procedure Tfrmmain.cmdConvertClick(Sender: TObject);
var
  imgl : TImageList;
  img : TBitmap;
  ico : TIcon;
begin
  //Icon to create.
  ico := TIcon.Create;
  //Load bitmap image to be stored into listimages.
  img  := TBitmap.Create;
  img.LoadFromFile('c:\out\ben.bmp');
  //Create the image list for 32x32 icons.
  imgl := TImageList.CreateSize(32,32);
  //Add bitmap and transparent color.
  imgl.AddMasked(img,RGBToColor(255,0,255));
  //Fetch icon
  imgl.GetIcon(0,ico);
  //Save icon to file
  ico.SaveToFile('c:\out\test.ico');

  //Free up memory.
  imgl.Free;
  img.Free;
  ico.Free;

end; 
« Last Edit: May 08, 2013, 09:28:09 am by BenJones »
When Your Dreams Come True.

pyros

  • New Member
  • *
  • Posts: 17
Re: Save Icon Form ImageList
« Reply #1 on: May 14, 2013, 05:39:59 pm »
Hi Ben,

I'm not sure, but you can tidy up your code a bit with this:

Code: [Select]
var
IconPicture: TPicture;
begin
IconPicture := TPicture.Create;
IconPicture.Bitmap.LoadFromFile('c:\out\ben.bmp');
IconPicture.Bitmap.SetSize(32, 32);
IconPicture.Icon.SaveToFile('c:\out\test.ico');
IconPicture.Free;

Sadly inserting the line:
Code: [Select]
IconPicture.Icon.PixelFormat := pf8bit;before calling SaveToFile only seems to hang execution.

Post back if you make any progress.

BenJones

  • Full Member
  • ***
  • Posts: 121
Re: Save Icon Form ImageList
« Reply #2 on: May 28, 2013, 08:19:45 am »
Thanks pyros if I find anything I let you know as I am still in need of this,
When Your Dreams Come True.

 

TinyPortal © 2005-2018