Board index » delphi » saving highcolor icons (>16 colors)

saving highcolor icons (>16 colors)

Hi

Im trying to save some highcolored icons. I get them from
ExtractIconEx, and i know they're high color, since i see it if i load
them into a TImageList (which im doing anyway)

Now, no matter how i try to use the TIcon object, they turn out to be
16 colors after a SaveToFile. Is there some magic involved in doing
this? After all, the impression i got about >16 colored icons is that
its a rather big hack

- Asbj?rn

 

Re:saving highcolor icons (>16 colors)


Quote
"Lord Crc" <lord...@hotmail.com> wrote in message news:3932f164.41839046@forums.inprise.com...
> Now, no matter how i try to use the TIcon object, they turn out to be
> 16 colors after a SaveToFile. Is there some magic involved in doing
> this? After all, the impression i got about >16 colored icons is that
> its a rather big hack

Could you post a small code fragment so we can see if we can
reproduce your problem?

--
efg

Earl F. Glynn     E-mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:saving highcolor icons (>16 colors)


That sounds strange. I don't have any problem loading or saving high-color
icons.

Besides, I'm actually working on an icon-unit with which it is able to deal
with icon groups.
It has got the following capabilities: load icon (group) from exe/dll/icon
files/bitmap files, save icon as icon file/bitmap file. It's almost in beta
stadium, I'm just working on a bug. If you're interested in it then send me
a mail (any answer will follow in about one week - you can't reach me at the
moment).

Bye, DPR

Re:saving highcolor icons (>16 colors)


Quote
In article <3932f164.41839...@forums.inprise.com>, Lord Crc wrote:
> Now, no matter how i try to use the TIcon object, they turn out to be
> 16 colors after a SaveToFile. Is there some magic involved in doing
> this? After all, the impression i got about >16 colored icons is that
> its a rather big hack

The Delphi TIcon class is very limited in this respect.

*  Icon files (.ICO) can contain several separate images at different
resolutions and sizes.  But if you load an Icon with LoadFromFile it
will load *only* the single image that matches your current screen
settings.  The algorithm that decides which image to load is a ghastly
tangle.  Have a look at ReadIcon in Graphics.pas, and try to figure out
what it's doing!

*  Seeing as Delphi only ever loads a single image from your .ICO file
when you call LoadFromFile, it can only write a single image when you
call SaveToFile.  All other images will be discarded.

*  And SaveToFile can only write 16 color icons, anyway.  Have a look
at the code for WriteIcon.  Especially the lines...

 InternalGetDIBSizes(IconInfo.hbmMask, MonoInfoSize, MonoBitsSize, 2);
 InternalGetDIBSizes(IconInfo.hbmColor, ColorInfoSize, ColorBitsSize,
16);

The '16' means 16 colors - in other words, Delphi can only write 16
color icons, no matter what the original resolution was.

All this means that if you want to manipulate icons in Delphi you've
got to code it all yourself.  The VCL doesn't do what you want.

Colin
e-mail :co...@wilsonc.demon.co.uk
web: http://www.wilsonc.demon.co.uk/delphi.htm

Re:saving highcolor icons (>16 colors)


On Mon, 29 May 2000 21:02:34 -0500, "Earl F. Glynn"

Quote
<EarlGl...@att.net> wrote:
>"Lord Crc" <lord...@hotmail.com> wrote in message news:3932f164.41839046@forums.inprise.com...

>> Now, no matter how i try to use the TIcon object, they turn out to be
>> 16 colors after a SaveToFile. Is there some magic involved in doing
>> this? After all, the impression i got about >16 colored icons is that
>> its a rather big hack

>Could you post a small code fragment so we can see if we can
>reproduce your problem?

Well, it went something like

ExtractIconEx(PChar(FileName), 0, LargeIcon, SmallIcon, 1);
Icon:= TIcon.Create;
Icon.Handle:= LargeIcon;
Icon.SaveToFile('myicon.ico');

btw, im a bit confused, when assigning the Handle, does the TIcon do a
DestroyIcon on it?

- Asbj?rn

Re:saving highcolor icons (>16 colors)


Quote
"Lord Crc" <lord...@hotmail.com> wrote in message news:39344826.43185000@forums.inprise.com...
> Well, it went something like

> ExtractIconEx(PChar(FileName), 0, LargeIcon, SmallIcon, 1);
> Icon:= TIcon.Create;
> Icon.Handle:= LargeIcon;
> Icon.SaveToFile('myicon.ico');

The example in The Tomes of Delphi 3:  Win32 Graphical API didn't
shed much light on this.  Instead of creating a TIcon, their example
shows using DrawIconEx and creating a TBitmap after using
ExtractIconEx.

Perhaps this will help:
http://community.borland.com/article/0,1410,16778,00.html

Quote
> btw, im a bit confused, when assigning the Handle, does the TIcon do a
> DestroyIcon on it?

Take a look at:
http://community.borland.com/article/0,1410,17458,00.html

--
efg

Earl F. Glynn     E-mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:saving highcolor icons (>16 colors)


On Tue, 30 May 2000 22:17:58 -0500, "Earl F. Glynn"

Quote
<EarlGl...@att.net> wrote:
>"Lord Crc" <lord...@hotmail.com> wrote in message news:39344826.43185000@forums.inprise.com...

>> Well, it went something like

>> ExtractIconEx(PChar(FileName), 0, LargeIcon, SmallIcon, 1);
>> Icon:= TIcon.Create;
>> Icon.Handle:= LargeIcon;
>> Icon.SaveToFile('myicon.ico');

>The example in The Tomes of Delphi 3:  Win32 Graphical API didn't
>shed much light on this.  Instead of creating a TIcon, their example
>shows using DrawIconEx and creating a TBitmap after using
>ExtractIconEx.

>Perhaps this will help:
>http://community.borland.com/article/0,1410,16778,00.html

>> btw, im a bit confused, when assigning the Handle, does the TIcon do a
>> DestroyIcon on it?

>Take a look at:
>http://community.borland.com/article/0,1410,17458,00.html

Thanks for the links.
Now, while we're at it, in the first link they do

ExtractIconEx('delphi32.exe', -1, nil, nil, 0);

Now, i tried doing that in d5, but no go, since the large and small
icon parameters are "var HICON", so, no go passing NIL... what i had
to do was

var
   dummyicon: HICON absolute nil;

which is not very neat... did someone not do their research when
writing that, or did i miss a point?

- Asbj?rn

Re:saving highcolor icons (>16 colors)


On Tue, 30 May 2000 11:46:34 +0100, Colin Wilson

Quote
<co...@wilsonc.demon.co.uk> wrote:
>*  And SaveToFile can only write 16 color icons, anyway.  Have a look
>at the code for WriteIcon.  Especially the lines...

> InternalGetDIBSizes(IconInfo.hbmMask, MonoInfoSize, MonoBitsSize, 2);
> InternalGetDIBSizes(IconInfo.hbmColor, ColorInfoSize, ColorBitsSize,
>16);

>The '16' means 16 colors - in other words, Delphi can only write 16
>color icons, no matter what the original resolution was.

>All this means that if you want to manipulate icons in Delphi you've
>got to code it all yourself.  The VCL doesn't do what you want.

Ahh...
Sometimes i find tracing through the VCL code really confusing...
Well, Copy 'n' paste works brilliant even in theese OO days :)

- Asbj?rn

Re:saving highcolor icons (>16 colors)


Quote
"Lord Crc" <lord...@hotmail.com> wrote in message news:393532be.16841484@forums.inprise.com...
> On Tue, 30 May 2000 22:17:58 -0500, "Earl F. Glynn"
> Now, while we're at it, in the first link they do

> ExtractIconEx('delphi32.exe', -1, nil, nil, 0);

> Now, i tried doing that in d5, but no go, since the large and small
> icon parameters are "var HICON", so, no go passing NIL... what i had
> to do was

I cannot explain your observation.  The example worked for me in
D3 or D5:

 type ThIconArray = array[0..0] of hIcon;
type PhIconArray = ^ThIconArray;

function ExtractIconExA(lpszFile: PAnsiChar;
                        nIconIndex: Integer;
                        phiconLarge : PhIconArray;
                        phiconSmall: PhIconArray;
                        nIcons: UINT): UINT; stdcall;
  external 'shell32.dll' name 'ExtractIconExA';

function ExtractIconExW(lpszFile: PWideChar;
                        nIconIndex: Integer;
                        phiconLarge: PhIconArray;
                        phiconSmall: PhIconArray;
                        nIcons: UINT): UINT; stdcall;
  external 'shell32.dll' name 'ExtractIconExW';

function ExtractIconEx(lpszFile: PAnsiChar;
                       nIconIndex: Integer;
                       phiconLarge : PhIconArray;
                       phiconSmall: PhIconArray;
                       nIcons: UINT): UINT; stdcall;
  external 'shell32.dll' name 'ExtractIconExA';

procedure TForm1.Button1Click(Sender: TObject);
  VAR
    NumIcons:  DWORD;
begin
 NumIcons :=
  ExtractIconEx('C:\Program Files\Borland\Delphi3\BIN\delphi32.exe',
                -1,
                nil,
                nil,
                0);
   ShowMessage(IntToStr(NumIcons))

end;

Re:saving highcolor icons (>16 colors)


On Wed, 31 May 2000 11:24:42 -0500, "Earl F. Glynn"

Quote
<EarlGl...@att.net> wrote:
>"Lord Crc" <lord...@hotmail.com> wrote in message news:393532be.16841484@forums.inprise.com...
>> On Tue, 30 May 2000 22:17:58 -0500, "Earl F. Glynn"

>> Now, while we're at it, in the first link they do

>> ExtractIconEx('delphi32.exe', -1, nil, nil, 0);

>> Now, i tried doing that in d5, but no go, since the large and small
>> icon parameters are "var HICON", so, no go passing NIL... what i had
>> to do was

>I cannot explain your observation.  The example worked for me in
>D3 or D5:

> type ThIconArray = array[0..0] of hIcon;
>type PhIconArray = ^ThIconArray;

>function ExtractIconExA(lpszFile: PAnsiChar;
>                        nIconIndex: Integer;
>                        phiconLarge : PhIconArray;
>                        phiconSmall: PhIconArray;
>                        nIcons: UINT): UINT; stdcall;
>  external 'shell32.dll' name 'ExtractIconExA';

Well, my shellapi goes

function ExtractIconExA(lpszFile: PAnsiChar; nIconIndex: Integer;
  var phiconLarge, phiconSmall: HICON; nIcons: UINT): UINT; stdcall;

Which means that i have to make the declaration myself, which i guess
is ok, but i guess they just threw the .h file through an automated
tool of some sort, without checking its validity.

- Asbj?rn

Other Threads