Does anyone know a class that can read multi-frame icons? An Internet search did not provide any information.
I tried to use IconTools 2.0 from Alan Peter Stotz, which correctly loads the icons into the list, but the bit depth for 8-bit and 4-bit icons is returned as 0. The bit file for the 32-bit and 24-bit icon frames returned correctly.
The icon itself displays correctly when viewed ... only the bitrate is incorrect for the specified bits.
EDIT # 2 Some untested code added to TLama comment:
function NumberOfIcons ( AFileName: string ): integer; var iNumberOfIcons: Integer; begin iNumberOfIcons := ExtractIcon ( hInstance, PChar ( AFilename ), UINT ( -1 ) ); Result := iNumberOfIcons; end; function ExtractAnIcon ( AFilename: string; AIndex: integer ): TBitmap; var icoHandle: HIcon; iBitmap: TBitmap; iIcon: TIcon; iNumberOfIcons, i: Integer; begin Result := nil; iBitmap := TBitMap.Create; iIcon := TIcon.Create; try // Get the number of Icons iNumberOfIcons := ExtractIcon ( hInstance, PChar ( AFilename ), UINT ( -1 ) ); // Extract the icon frame icoHandle := ExtractIcon ( hInstance, PChar ( AFileName ), AIndex ); iIcon.Handle := icoHandle; iBitmap.Width := iIcon.Width; iBitmap.Height := iIcon.Height; // Draw the icon on your bitmap DrawIcon ( iBitmap.Canvas.Handle, 0, 0, iIcon.Handle ); Result := iBitmap; finally iIcon.Free; end; end; function PixelFormatToBitDepth ( APixelFormat: TPixelFormat ): integer; // Convert TPixelFormat to integer begin Result := -1; case APixelFormat of pf32Bit: Result := 32; pf24bit: Result := 24; pf8bit: Result := 8; pf4Bit: Result := 4; pf1bit: Result := 1; end; end;
Am I on the right track? In my testing, I now get 1 icon, but the NumberOfIcons function returns 1?
Edit # 3 According to the help file "If the file is an .ICO file, the return value of ExtractIcon is 1." So, what method can be used to get the number of icons in the ico file?
source share