Board index » delphi » icons w/ more than 16 colors

icons w/ more than 16 colors

I am trying to use TIcon.SaveToFile to extract icons from DLLs to .ICO
files. The problem is that the TIcon object can only save ICO files w/ up to
16 colors.

How do I work around this problem?

Given an icon handle (HICON), how do I create an ICO file that has the same
# of colors as the original?

I am using ExtractIcon to get the icon handle.

Alex

 

Re:icons w/ more than 16 colors


Quote
In article <93eq4o$7...@bornews.inprise.com>, Alex Simonetti wrote:
> I am trying to use TIcon.SaveToFile to extract icons from DLLs to .ICO
> files. The problem is that the TIcon object can only save ICO files w/ up to
> 16 colors.

> How do I work around this problem?

> Given an icon handle (HICON), how do I create an ICO file that has the same
> # of colors as the original?

There are a number of problems with TIcon...

1.  It can only hold one icon image, but a .ICO file, or an icon held in an
ICON resource in a DLL can have several images at different resolutions.

2.  TIcon can't handle icons with more than 256 colours.

3.  TIcon will only correctly save 256 color icons if your screen resolution
is set to 256 colors.  If it's set to more (ie. most people!) or less, you'll
only get 16 colors.

etc.

And you've got to remember that HICON contains a single icon image, so if you
do anything HICON based  - using things like CreateIconFromResourceEx, you
will only get the icon with the appropriate resolution for your screen.

The best way to do what you want is to load and decode the ICON resources into
their separate images, without using TIcon or HICON, then save the .ICO file
by writing a ICONDIR structure, followed by the icon information for each
image.

You can download a free Resource Editor from my website that lets you extract
.ICO files from dlls.  It's free and comes with all source, so you can maybe
pinch some code from there...

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

Re:icons w/ more than 16 colors


<SNIP>

Quote

> 3.  TIcon will only correctly save 256 color icons if your screen resolution
> is set to 256 colors.  If it's set to more (ie. most people!) or less, you'll
> only get 16 colors.

<SNIP>

Colin,
  Are you sure about this???

The WriteIcon procedure in Graphics.pas is limited to writing
icons in 16 colors only by virtue of this code:

procedure WriteIcon(Stream: TStream; Icon: HICON; WriteLength: Boolean);
<SNIP>
    InternalGetDIBSizes(IconInfo.hbmMask, MonoInfoSize, MonoBitsSize, 2);
    InternalGetDIBSizes(IconInfo.hbmColor, ColorInfoSize, ColorBitsSize, 16);
<SNIP>
      InternalGetDIB(IconInfo.hbmMask, 0, MonoInfo^, MonoBits^, 2);
      InternalGetDIB(IconInfo.hbmColor, 0, ColorInfo^, ColorBits^, 16);
<SNIP>
end;

Re:icons w/ more than 16 colors


TjvIcon is a TComponent descendant with public methods: Create Icon from Bitmap,
Save Icon with 16 colors, Save Icon with 256 colors, Save Bitmap as 16 color
Icon,
Save Bitmap as 256 color Icon.

Download it from:
http://jansfreeware.com/jfdelphi.htm

Quote
> I am trying to use TIcon.SaveToFile to extract icons from DLLs to .ICO
> files. The problem is that the TIcon object can only save ICO files w/ up to
> 16 colors.

> How do I work around this problem?

Re:icons w/ more than 16 colors


Quote
In article <93fk2o$4...@bornews.inprise.com>, MrBaseball34 wrote:
> > 3.  TIcon will only correctly save 256 color icons if your screen resolution
> > is set to 256 colors.  If it's set to more (ie. most people!) or less, you'll
> > only get 16 colors.

> <SNIP>

> Colin,
>   Are you sure about this???

> The WriteIcon procedure in Graphics.pas is limited to writing
> icons in 16 colors only by virtue of this code:

Oops I was muddling it up with TBitmap there.  

TBitmap has a bug where if you set the pixel format from > pf8Bit to pf8Bit you
end up with 16 colours instead of 256 because of the calls to
CreateHalftonePalette in TBitmap.PaletteNeeded and TBitmap.SetPixelFormat.  
CreateHalftonePalette only returns a 256 color palette if your screen color depth
is set to 256 colors.

You're right - TIcon will only write 16 colour icons...

To make up for it, I've upload a unit that contains TExIcon and TExCursor to the
Attachments group.

*  It supports icons with multiple images.
*  It supports icons of any size, including 'non-standard' sizes
*  It correctly displays icons with > 256 colours on NT 4 systems.
*  It's Assign method will accept any TGraphic, including TBitmap, etc.
*  It has a PixelFormat property
*  It supports SaveToClipboardFormat and LoadFromClipboardFormat

etc.

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

Re:icons w/ more than 16 colors


Thank you folks.

I've already tried TjvIcon, with some good results.

I am now browsing through Colin's site (nice one, BTW!) and downloading the
graphics units.

Thanks.

Alex

Quote
"Colin Wilson" <co...@wilsonc.demon.co.uk> wrote in message

news:VA.00000f53.1df27b5c@wilsonc.demon.co.uk...
Quote
> In article <93fk2o$4...@bornews.inprise.com>, MrBaseball34 wrote:
> > > 3.  TIcon will only correctly save 256 color icons if your screen
resolution
> > > is set to 256 colors.  If it's set to more (ie. most people!) or less,
you'll
> > > only get 16 colors.

> > <SNIP>

> > Colin,
> >   Are you sure about this???

> > The WriteIcon procedure in Graphics.pas is limited to writing
> > icons in 16 colors only by virtue of this code:

> Oops I was muddling it up with TBitmap there.

> TBitmap has a bug where if you set the pixel format from > pf8Bit to
pf8Bit you
> end up with 16 colours instead of 256 because of the calls to
> CreateHalftonePalette in TBitmap.PaletteNeeded and TBitmap.SetPixelFormat.
> CreateHalftonePalette only returns a 256 color palette if your screen
color depth
> is set to 256 colors.

> You're right - TIcon will only write 16 colour icons...

> To make up for it, I've upload a unit that contains TExIcon and TExCursor
to the
> Attachments group.

> *  It supports icons with multiple images.
> *  It supports icons of any size, including 'non-standard' sizes
> *  It correctly displays icons with > 256 colours on NT 4 systems.
> *  It's Assign method will accept any TGraphic, including TBitmap, etc.
> *  It has a PixelFormat property
> *  It supports SaveToClipboardFormat and LoadFromClipboardFormat

> etc.

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

Re:icons w/ more than 16 colors


Quote
In article <93hhl3$p...@bornews.inprise.com>, Alex Simonetti wrote:
> am now browsing through Colin's site (nice one, BTW!) and downloading the
> graphics units.

The file I put in the Attachments newsgroup is different from anything on
my website.

1.  It works better.
2.  It's stand-alone, and doesn't require a heap of other units.

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

Re:icons w/ more than 16 colors


It requires unitExGraphics.pas...Where is that file?
Quote
> The file I put in the Attachments newsgroup is different from anything on
> my website.

> 1.  It works better.
> 2.  It's stand-alone, and doesn't require a heap of other units.

Re:icons w/ more than 16 colors


Quote
In article <93i4uq$o...@bornews.inprise.com>, MrBaseball34 wrote:
> It requires unitExGraphics.pas...Where is that file?

Sorry about that - I've re-uploaded it without the dependency.

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

Other Threads