Get ICO from TGDIPPictureContainer

Hi,


I have a couple of ico format images stored in a TGDIPPictureContainer and I am wondering how to retrieve these images to be used in a TImageList. The ICO file only contains 1 icon in 48x48 pixel format.

I have tried streaming it to a TMemoryStream but I get the following error when I read the stream back.

Container1.Items.Items[index].Picture.SaveToStream(MS);
Icon.LoadFromStream(MS) <----------- This gives me a "Stream Read Error"

Thx.

/jeffc

Please define Icon, what type has icon?

Hi, 

Icon is TIcon. I also tried using TPicture.Icon but I also get the same error.

/jeffc

You need to set Position := 0 on the MemoryStream:


var
  ico: TIcon;
  ms: TMemoryStream;
begin

  ico := TIcon.Create;
  ms := TMemoryStream.Create;
  GDIPPictureContainer1.FindPicture('0').SaveToStream(ms);
  ms.Position := 0;
  ico.LoadFromStream(ms);
  ico.SaveToFile('C:\temp\test.ico');
  ms.Free;
  ico.Free;

Hi,


Thank you, this has resolved the error.