How to convert 256x256 ICO file to BMP in Delphi 2010?

Hi,

I would like to convert an ICO file (icon size 256x256) to BMP file.
I get EOutOfResources exception in the line: "Bitmap.Width := Icon.Width;"
Is it not possible?

Regards
Eric


Procedure ConvertIcoToBmpTest;
var
   Icon : TIcon;
   Bitmap : TBitmap;
begin
   Icon := TIcon.Create;
   try
     Bitmap := TBitmap.Create;
     try
       Icon.LoadFromFile('c:\temp\bigicon.ico') ;
       Bitmap.Width := Icon.Width;
       Bitmap.Height := Icon.Height;
       Bitmap.Canvas.Draw(0, 0, Icon ) ;
       Bitmap.SaveToFile('c:\temp\bigicon.bmp') ;
     finally
        Bitmap.Free;
     end;
   finally
      Icon.Free;
   end;

end;
0
Eric
7/28/2010 7:55:48 PM
embarcadero.delphi.nativeapi 1236 articles. 1 followers. Follow

22 Replies
1129 Views

Similar Articles

[PageSpeed] 13

> {quote:title=Eric Holzer wrote:}{quote}
> Hi,
> 
> I would like to convert an ICO file (icon size 256x256) to BMP file.
> I get EOutOfResources exception in the line: "Bitmap.Width := Icon.Width;"
> Is it not possible?
> 
> Regards
> Eric
> 
> 
> Procedure ConvertIcoToBmpTest;
> var
>    Icon : TIcon;
>    Bitmap : TBitmap;
> begin
>    Icon := TIcon.Create;
>    try
>      Bitmap := TBitmap.Create;
>      try
>        Icon.LoadFromFile('c:\temp\bigicon.ico') ;
>        Bitmap.Width := Icon.Width;
>        Bitmap.Height := Icon.Height;
>        Bitmap.Canvas.Draw(0, 0, Icon ) ;
>        Bitmap.SaveToFile('c:\temp\bigicon.bmp') ;
>      finally
>         Bitmap.Free;
>      end;
>    finally
>       Icon.Free;
>    end;
> 
> end;

Something like this (hope it helps you) :
{code}

type
  PIconDirectoryEntry = ^TIconDirectoryEntry;
  TIconDirectoryEntry = packed record
    bWidth        : Byte;
    bHeight       : Byte;
    bColorCount   : Byte;
    bReserved     : Byte;
    wPlanes       : Word;
    wBitCount     : Word;
    dwBytesInRes  : LongInt;
    wID           : Word;
  end;

  PIconDir = ^TIconDir;
  TIconDir = packed record
    idReserved : Word;
    idType     : Word;
    idCount    : Word;
  end;

  PIconResInfo = ^TIconResInfo;
  TIconResInfo = packed record
    bWidth        : Byte;        // Largeur, en pixels
    bHeight       : Byte;        // Hauteur, en pixels
    bColorCount   : Byte;        // Nombre de couleurs de l' image (0 if >=8bpp)
    bReserved     : byte;        // Reserved ( 0)
    wPlanes       : Word;        // Color Planes
    wBitCount     : Word;        // Bits per pixel
    dwBytesInRes  : DWord;       // Combien d'octets dans la ressource?
  end;

  PFileIconResInfo = ^TFileIconResInfo;
  TFileIconResInfo = packed record
    ResInfo       : TIconResInfo;
    dwImageOffset : DWord;         // Offset de l'image dans le fichier
  end;

  TResourceIconResInfo = packed record
    ResInfo       : TIconResInfo;
    ID            : Word;          //  ID de la ressource
  end;

function GetIconeBitmap(const Fichier :string; BkgCoul : TColor): TBitmap;
var
  hauteur, largeur : integer;
  Icone : HICON;

begin
  Icone := IconeIcoFileMaxRes(Fichier, hauteur, largeur);
  if (largeur < 1) or (hauteur < 1) then
    begin
      largeur := 1;
      hauteur := 1;
    end;
  Result := TBitmap.Create;
  with Result do
    begin
      PixelFormat := pf32bit;
      Canvas.Brush.Color := BkgCoul;
      Width := largeur;
      Height := hauteur;
      if Icone <> 0 then
        begin
          DrawIconEx(Canvas.Handle, 0, 0, Icone, Width, Height, 0, 0, DI_NORMAL);
          DestroyIcon(Icone);
        end;
    end;
end;

function IconeIcoFileMaxRes(const Fichier :string; var hauteur, largeur : integer): HICON;

var
  HdlFichierIco : hFile;
  IconDirLire     : TIconDir;
  OctetsLus : cardinal;
  FileIconResInfo : TFileIconResInfo;
  PFIRI : PFileIconResInfo;
  i : integer;
  maxres : integer;
  Buffer : PChar;
  offset : integer;

begin
  Result := 0;
  HdlFichierIco := 0;
  try
    HdlFichierIco := CreateFile(PChar(Fichier),
                         GENERIC_READ,
                         FILE_SHARE_READ,
                         nil,
                         OPEN_EXISTING,
                         FILE_ATTRIBUTE_COMPRESSED or FILE_ATTRIBUTE_HIDDEN or
                         FILE_ATTRIBUTE_READONLY or FILE_ATTRIBUTE_SYSTEM	,
                         0);
    if HdlFichierIco = INVALID_HANDLE_VALUE then Exit;

    //SetFilePointer(HdlFichierIco, 0, nil, FILE_BEGIN);
    if ReadFile(HdlFichierIco, IconDirLire, SizeOf(TIconDir), OctetsLus, nil)
      and (OctetsLus <> 0) then
      begin
        PFIRI := PFileIconResInfo(SizeOf(TIconDir));
        maxres := 0;
        offset := 0;
        for i := 0 to IconDirLire.idCount - 1 do begin
          SetFilePointer(HdlFichierIco, integer(PFIRI), nil, FILE_BEGIN);
          if ReadFile(HdlFichierIco, FileIconResInfo, SizeOf(TFileIconResInfo), OctetsLus, nil)
            and (OctetsLus <> 0) then
            begin
              with FileIconResInfo.ResInfo do begin
                if integer(dwBytesInRes) > maxres then
                  begin
                    maxres := dwBytesInRes;
                    largeur := bWidth;
                    if largeur = 0 then largeur := 256;
                    hauteur := bHeight;
                    if hauteur = 0 then hauteur := 256;
                    offset := FileIconResInfo.dwImageOffset;
                  end;
              end;
              inc(PFIRI);
            end
          else
            begin
              CloseHandle(HdlFichierIco);
              exit;
            end;
        end;
        if hauteur = 2 * largeur then hauteur := largeur;
        GetMem(Buffer, maxres);
        try
          SetFilePointer(HdlFichierIco, offset, nil, FILE_BEGIN);
          if ReadFile(HdlFichierIco, Buffer^, maxres, OctetsLus, nil)
            and (OctetsLus <> 0) then
            Result := CreateIconFromResourceEx(PByte(Buffer), maxres, true, $00030000,
                                     largeur, hauteur, LR_DEFAULTCOLOR);
        finally
          FreeMem(Buffer, maxres);
        end;
      end;
  finally
    CloseHandle(HdlFichierIco);
  end;
end;

{code}
--
http://www.codeppc.com/telechargements/themegence/themegence.htm
http://www.codeppc.com/telechargements/msceinf/msceinf.htm
0
benoit
7/28/2010 8:17:08 PM
Eric Holzer wrote:

> Hi,
> 
> I would like to convert an ICO file (icon size 256x256) to BMP file.
> I get EOutOfResources exception in the line: "Bitmap.Width :=
> Icon.Width;" Is it not possible?
> 

The code you've posted is correct. To test the ico file first please
try to load it into a TImage just to verify that Delphi can process the
file.
0
Lajos
7/28/2010 8:19:49 PM
> {quote:title=benoit thonnart wrote:}{quote}
> 
> Something like this (hope it helps you) :
> {code}
> 
> type
>   PIconDirectoryEntry = ^TIconDirectoryEntry;
>   TIconDirectoryEntry = packed record
>     bWidth        : Byte;
>     bHeight       : Byte;
>     bColorCount   : Byte;
>     bReserved     : Byte;
>     wPlanes       : Word;
>     wBitCount     : Word;
>     dwBytesInRes  : LongInt;
>     wID           : Word;
>   end;
> 
>   PIconDir = ^TIconDir;
>   TIconDir = packed record
>     idReserved : Word;
>     idType     : Word;
>     idCount    : Word;
>   end;
> 
>   PIconResInfo = ^TIconResInfo;
>   TIconResInfo = packed record
>     bWidth        : Byte;        // Largeur, en pixels
>     bHeight       : Byte;        // Hauteur, en pixels
>     bColorCount   : Byte;        // Nombre de couleurs de l' image (0 if >=8bpp)
>     bReserved     : byte;        // Reserved ( 0)
>     wPlanes       : Word;        // Color Planes
>     wBitCount     : Word;        // Bits per pixel
>     dwBytesInRes  : DWord;       // Combien d'octets dans la ressource?
>   end;
> 
>   PFileIconResInfo = ^TFileIconResInfo;
>   TFileIconResInfo = packed record
>     ResInfo       : TIconResInfo;
>     dwImageOffset : DWord;         // Offset de l'image dans le fichier
>   end;
> 
>   TResourceIconResInfo = packed record
>     ResInfo       : TIconResInfo;
>     ID            : Word;          //  ID de la ressource
>   end;
> 
> function GetIconeBitmap(const Fichier :string; BkgCoul : TColor): TBitmap;
> var
>   hauteur, largeur : integer;
>   Icone : HICON;
> 
> begin
>   Icone := IconeIcoFileMaxRes(Fichier, hauteur, largeur);
>   if (largeur < 1) or (hauteur < 1) then
>     begin
>       largeur := 1;
>       hauteur := 1;
>     end;
>   Result := TBitmap.Create;
>   with Result do
>     begin
>       PixelFormat := pf32bit;
>       Canvas.Brush.Color := BkgCoul;
>       Width := largeur;
>       Height := hauteur;
>       if Icone <> 0 then
>         begin
>           DrawIconEx(Canvas.Handle, 0, 0, Icone, Width, Height, 0, 0, DI_NORMAL);
>           DestroyIcon(Icone);
>         end;
>     end;
> end;
> 
> function IconeIcoFileMaxRes(const Fichier :string; var hauteur, largeur : integer): HICON;
> 
> var
>   HdlFichierIco : hFile;
>   IconDirLire     : TIconDir;
>   OctetsLus : cardinal;
>   FileIconResInfo : TFileIconResInfo;
>   PFIRI : PFileIconResInfo;
>   i : integer;
>   maxres : integer;
>   Buffer : PChar;
>   offset : integer;
> 
> begin
>   Result := 0;
>   HdlFichierIco := 0;
>   try
>     HdlFichierIco := CreateFile(PChar(Fichier),
>                          GENERIC_READ,
>                          FILE_SHARE_READ,
>                          nil,
>                          OPEN_EXISTING,
>                          FILE_ATTRIBUTE_COMPRESSED or FILE_ATTRIBUTE_HIDDEN or
>                          FILE_ATTRIBUTE_READONLY or FILE_ATTRIBUTE_SYSTEM	,
>                          0);
>     if HdlFichierIco = INVALID_HANDLE_VALUE then Exit;
> 
>     //SetFilePointer(HdlFichierIco, 0, nil, FILE_BEGIN);
>     if ReadFile(HdlFichierIco, IconDirLire, SizeOf(TIconDir), OctetsLus, nil)
>       and (OctetsLus <> 0) then
>       begin
>         PFIRI := PFileIconResInfo(SizeOf(TIconDir));
>         maxres := 0;
>         offset := 0;
>         for i := 0 to IconDirLire.idCount - 1 do begin
>           SetFilePointer(HdlFichierIco, integer(PFIRI), nil, FILE_BEGIN);
>           if ReadFile(HdlFichierIco, FileIconResInfo, SizeOf(TFileIconResInfo), OctetsLus, nil)
>             and (OctetsLus <> 0) then
>             begin
>               with FileIconResInfo.ResInfo do begin
>                 if integer(dwBytesInRes) > maxres then
>                   begin
>                     maxres := dwBytesInRes;
>                     largeur := bWidth;
>                     if largeur = 0 then largeur := 256;
>                     hauteur := bHeight;
>                     if hauteur = 0 then hauteur := 256;
>                     offset := FileIconResInfo.dwImageOffset;
>                   end;
>               end;
>               inc(PFIRI);
>             end
>           else
>             begin
>               CloseHandle(HdlFichierIco);
>               exit;
>             end;
>         end;
>         if hauteur = 2 * largeur then hauteur := largeur;
>         GetMem(Buffer, maxres);
>         try
>           SetFilePointer(HdlFichierIco, offset, nil, FILE_BEGIN);
>           if ReadFile(HdlFichierIco, Buffer^, maxres, OctetsLus, nil)
>             and (OctetsLus <> 0) then
>             Result := CreateIconFromResourceEx(PByte(Buffer), maxres, true, $00030000,
>                                      largeur, hauteur, LR_DEFAULTCOLOR);
>         finally
>           FreeMem(Buffer, maxres);
>         end;
>       end;
>   finally
>     CloseHandle(HdlFichierIco);
>   end;
> end;
> 
> {code}

It was very fast and it works well, thanks!!!

Regards
Eric
0
Eric
7/28/2010 8:31:36 PM
> {quote:title=Lajos Juhasz wrote:}{quote}
> 
> The code you've posted is correct. To test the ico file first please
> try to load it into a TImage just to verify that Delphi can process the
> file.

The code is correct but it does not works with icons 256x256.
The using of the TImage make the same result with EOutOfResources exception.

Eric
0
Eric
7/28/2010 8:35:21 PM
<Eric Holzer> wrote in message news:266586@forums.embarcadero.com...

>       Bitmap.Width := Icon.Width;
>       Bitmap.Height := Icon.Height;
>       Bitmap.Canvas.Draw(0, 0, Icon ) ;

Try using the Assign() method instead.  TIcon known how to assign itself to 
a TBitmap, ie:

{code:delphi}
Procedure ConvertIcoToBmpTest;
var
  Icon : TIcon;
  Bitmap : TBitmap;
begin
  Icon := TIcon.Create;
  try
    Icon.LoadFromFile('c:\temp\bigicon.ico') ;
    Bitmap := TBitmap.Create;
    try
      Bitmap.Assign(Icon);
      Bitmap.SaveToFile('c:\temp\bigicon.bmp') ;
    finally
      Bitmap.Free;
    end;
  finally
    Icon.Free;
  end;
end;
{code}

-- 
Remy Lebeau (TeamB)
0
Remy
7/28/2010 9:04:15 PM
<Eric Holzer> wrote in message news:266614@forums.embarcadero.com...

> The code is correct but it does not works with icons 256x256.
> The using of the TImage make the same result with
> EOutOfResources exception.

Then the problem is in the icon itself.

-- 
Remy Lebeau (TeamB)
0
Remy
7/28/2010 9:27:36 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Try using the Assign() method instead.  TIcon known how to assign itself to 
> a TBitmap, ie:
> 
> {code:delphi}
> Procedure ConvertIcoToBmpTest;
> var
>   Icon : TIcon;
>   Bitmap : TBitmap;
> begin
>   Icon := TIcon.Create;
>   try
>     Icon.LoadFromFile('c:\temp\bigicon.ico') ;
>     Bitmap := TBitmap.Create;
>     try
>       Bitmap.Assign(Icon);
>       Bitmap.SaveToFile('c:\temp\bigicon.bmp') ;
>     finally
>       Bitmap.Free;
>     end;
>   finally
>     Icon.Free;
>   end;
> end;
> {code}
> 
> -- 
> Remy Lebeau (TeamB)


EOutOfResources in the line "Bitmap.Assign(Icon);".
The icon is OK. Delphi 2010 can not load such icons.

Eric
0
Eric
7/28/2010 9:40:02 PM
<Eric Holzer> wrote in message news:266661@forums.embarcadero.com...

> EOutOfResources in the line "Bitmap.Assign(Icon);".
> The icon is OK. Delphi 2010 can not load such icons.

Please post the actual icon file.

-- 
Remy Lebeau (TeamB)
0
Remy
7/28/2010 11:37:21 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> <Eric Holzer> wrote in message news:266661@forums.embarcadero.com...
> 
> > EOutOfResources in the line "Bitmap.Assign(Icon);".
> > The icon is OK. Delphi 2010 can not load such icons.
> 
> Please post the actual icon file.
> 
> -- 
> Remy Lebeau (TeamB)

I think that the reason why this message appears is because of the with and height (for icons 256x256) stored in the ResInfo is 0. That's why I wrote my functions. I think that the VCL does not handle thes large icons. Here I change with and height to 256 if it is 0 :

{code}
              with FileIconResInfo.ResInfo do begin
                if integer(dwBytesInRes) > maxres then
                  begin
                    maxres := dwBytesInRes;
                    largeur := bWidth;
                    if largeur = 0 then largeur := 256;
                    hauteur := bHeight;
                    if hauteur = 0 then hauteur := 256;
                    offset := FileIconResInfo.dwImageOffset;
                  end;
{code}
--
http://www.codeppc.com/telechargements/themegence/themegence.htm
http://www.codeppc.com/telechargements/msceinf/msceinf.htm
0
benoit
7/29/2010 8:08:18 AM
Hello!

Try this!

{code}
unit Unit1;

interface



uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function IS_INTRESOURCE(lpszType: PChar): Boolean;
begin
  Result := ((DWORD(lpszType) shr 16) = 0);
end;


var
  IconsFound: Integer;
  LastResNum: Integer;
  LastResName: string;
  function EnumIcon(Module: THandle; ResType: PChar; ResName: PChar; Param: Pointer): Bool; export; stdcall;
   begin
    LastResNum:=-1;
    LastResName:='';
    if IS_INTRESOURCE(ResName) then LastResNum:=Integer(ResName)
    else LastResName:=string(ResName);
     if IconsFound = Integer(Param) then
      Result:=False
     else
      Result:=True;
     Inc(IconsFound);
   end;

function ExtractIconVista(
IconLocation: string;
out HandleIconOut: HIcon;
IconNum: Integer=0;
IconNumAsIndex: Boolean=False;
cxDesired: Cardinal = 0;
cyDesired: Cardinal = 0;
Flags: Dword = 0
{
LR_DEFAULTCOLOR = $0000;
  LR_MONOCHROME = $0001;
  LR_COLOR = $0002;
  LR_COPYRETURNORG = $0004;
  LR_COPYDELETEORG = $0008;
  LR_LOADFROMFILE = $0010;
  LR_LOADTRANSPARENT = $0020;
  LR_DEFAULTSIZE = $0040;
  LR_VGACOLOR = $0080;
  LR_LOADMAP3DCOLORS = $1000;
  LR_CREATEDIBSECTION = $2000;
  LR_COPYFROMRESOURCE = $4000;
  LR_SHARED = $8000;
}
): Boolean;
   var
    hLib,hRes,lRes,hResIcon,lResIcon: Cardinal;
    MRes: PAnsiChar;
    lIcon: Integer;
   begin
    Result:=False;
    hLib:=LoadLibraryEx(PChar(IconLocation), 0, LOAD_LIBRARY_AS_DATAFILE);
    if hLib <> 0 then
     try
      IconsFound:=0;
     if IconNumAsIndex=False then
      EnumResourceNames(hLib, RT_GROUP_ICON, @EnumIcon, IconNum)
     else
      LastResNum:=IconNum;
      if LastResNum=-1 then
      hRes:=FindResource(hLib, PChar(LastResName), RT_GROUP_ICON)
      else
      hRes:=FindResource(hLib, MakeIntResource(LastResNum) , RT_GROUP_ICON);
      if hRes <> 0 then try
       lRes:=LoadResource(hLib, hRes);
       if lRes <> 0 then try
         if cxDesired+cyDesired<=1 then
          lIcon:=LookupIconIDFromDirectory(LockResource(lRes), True)
         else
          lIcon:=LookupIconIDFromDirectoryEx(LockResource(lRes), True, cxDesired,cyDesired,Flags);
          MRes:=MakeIntResource(lIcon);
          if lIcon <> 0 then begin hResIcon := FindResource(hLib, MRes, RT_ICON);
           if hResIcon <> 0 then try
            lResIcon := LoadResource(hLib, hResIcon);
            if lResIcon <> 0 then try
              HandleIconOut:=CreateIconFromResourceEx(LockResource(lResIcon),
              SizeOfResource(hLib, hResIcon),
               True, $030000, cxDesired, cyDesired, Flags);
              Result:=True;
            finally
              UnLockResource(lResIcon);
            end;
           finally
            FreeResource(hResIcon);
           end;
          end;
       finally
         UnlockResource(lRes);
       end;
      finally
        FreeResource(hRes);
      end;
     finally
     FreeLibrary(hLib);
     end;
   end;

procedure TForm1.Button1Click(Sender: TObject);
var
IconLocation: string;
ErgebnisIcon: TIcon;
ErgebnisIconH: hIcon;
Bmp: TBitmap;
begin
IconLocation:='C:\Program Files\Movie Maker\DVDMaker.exe';
ErgebnisIcon:=TIcon.Create;
ExtractIconVista(IconLocation,ErgebnisIconH,0,False,256,256,LR_VGACOLOR);
ErgebnisIcon.Handle:=ErgebnisIconH;
bmp:=TBitmap.Create;
try
bmp.PixelFormat:=pf32bit;
bmp.Width:=256;
bmp.Height:=256;
bmp.Canvas.Draw(0,0,ErgebnisIcon);
bmp.SaveToFile('e:\sample.bmp');
Form1.Canvas.Draw(0,0,ErgebnisIcon);
finally
bmp.Free;
end;
ErgebnisIcon.Free;
end;

end.

{code}

Tested with Vista x64.

bye, Alberto
0
Alberto
7/29/2010 3:36:45 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> 
> Please post the actual icon file.
> 


You can find the icon file in the attachment forum.

Eric
0
Eric
7/29/2010 7:19:46 PM
> {quote:title=Alberto Briattore wrote:}{quote}
> Hello!
> 
> Try this!
> 

Hi Alberto,

thanks for the example how to extract vista icon from the exe file. It works fine.
But it was not my question. I need to extract an 256x256 icon from the ICO file and convert to BMP.

Regards
Eric
0
Eric
7/29/2010 7:24:16 PM
<benoit thonnart> wrote in message news:266834@forums.embarcadero.com...

> I think that the reason why this message appears is
> because of the with and height (for icons 256x256)
> stored in the ResInfo is 0.

What does the ICO standard say about that?

-- 
Remy Lebeau (TeamB)
0
Remy
7/29/2010 7:27:15 PM
<Eric Holzer> wrote in message news:266586@forums.embarcadero.com...

> I would like to convert an ICO file (icon size 256x256) to
> BMP file.  I get EOutOfResources exception in the line:
> "Bitmap.Width := Icon.Width;" Is it not possible?

When I run your code in D2010 on XP, it does not crash for me. 
TIcon.LoadFromFile() succeeds, but the TIcon's Width and Height both report 
0 (because they are 0 in the icon's header, which is wrong).  A .bmp file is 
produced without error.  However, XP cannot preview either file.  Changing the
icon's header to report its demensions as 256x256 correctly instead of 0x0
fixes the problem. There is nothing special about 256x256 icons in regards
to the ICO specification, AFAIK. You simply have a corrupted file to begin with.

-- 
Remy Lebeau (TeamB)
0
Remy
7/29/2010 8:06:06 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> <Eric Holzer> wrote in message news:266586@forums.embarcadero.com...
> 
> > I would like to convert an ICO file (icon size 256x256) to
> > BMP file.  I get EOutOfResources exception in the line:
> > "Bitmap.Width := Icon.Width;" Is it not possible?
> 
> When I run your code in D2010 on XP, it does not crash for me. 
> TIcon.LoadFromFile() succeeds, but the TIcon's Width and Height both report 
> 0 (because they are 0 in the icon's header, which is wrong).  A .bmp file is 
> produced without error.  However, XP cannot preview either file.  Changing the
> icon's header to report its demensions as 256x256 correctly instead of 0x0
> fixes the problem. There is nothing special about 256x256 icons in regards
> to the ICO specification, AFAIK. You simply have a corrupted file to begin with.
> 
> -- 
> Remy Lebeau (TeamB)

Hello Remy,

I am sorry to say to an expert, that I really appreciate for his kindness and competence, that he is wrong. 
I do not think that the file is corrupted. See in the Microsoft DLL Imageres.dll which comes with Vista and extract an icon with 256x256 image and you will see that width and height is 0 for it.

Many years ago I bought the excellent program from Impact Software : MicroAngelo. I think that they are expert in icons. I have found on internet information from a programmer of this product :

"
+As to your question, "Is it possible to add icons bigger than 256x256":  The file format of the icon resource has remained standard since its inception.  The header (directory) at the beginning of the resource has one byte each allocated for the width and height.  One byte can only store values from 0 to 255.  So the 256x256 images actually appear as 0x0 in the directory of the resource.  Of course there is more information further into the resource, so it is possible to enhance new Windows code to be aw
are of 256x256 images (like Vista) and investigate further.  Only MSFT would know if supporting larger images were planned (not accidentally supported...).  My best guess is that 256 will remain the top size for some time, at the very least until older versions of Windows are phased out.+
"

Reference : http://social.msdn.microsoft.com/Forums/en-US/windowsuidevelopment/thread/021ef80e-cc62-4fb5-bcfb-0a38be85b165

Another reference, but in french... :  http://msdn.microsoft.com/fr-fr/magazine/cc546571.aspx


Thanks again for your kindness and competence.
--
http://www.codeppc.com/telechargements/themegence/themegence.htm
http://www.codeppc.com/telechargements/msceinf/msceinf.htm
0
benoit
7/29/2010 8:36:53 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> When I run your code in D2010 on XP, it does not crash for me. 
> TIcon.LoadFromFile() succeeds, but the TIcon's Width and Height both report 
> 0 (because they are 0 in the icon's header, which is wrong).  A .bmp file is 
> produced without error.  However, XP cannot preview either file.  Changing the
> icon's header to report its demensions as 256x256 correctly instead of 0x0
> fixes the problem. There is nothing special about 256x256 icons in regards
> to the ICO specification, AFAIK. You simply have a corrupted file to begin with.
> 

Thanks for your explanation.
Probably it is know problem or quasi standard because I can open the icon in other programs without problems.
I have created now very simple 256x256 icon with the current Axialis IconWorkshop - the same exception in my and your code.

Eric
0
Eric
7/29/2010 8:39:44 PM
<benoit thonnart> wrote in message news:267174@forums.embarcadero.com...

> I do not think that the file is corrupted. See in the Microsoft
> DLL Imageres.dll which comes with Vista and extract an
> icon with 256x256 image and you will see that width and
> height is 0 for it.

Searching around, I came across this page:

http://www.axialis.com/tutorials/tutorial-vistaicons.html

Basically, it says that Vista-style 256x256 PNG-compressed icons are not 
supported by versions of Windows earlier than Vista, or by third-party code 
that only support XP-style icons.  Vista-style 16x16, 32x32, 48x48, and 
256x256 (uncompressed) icons are backwards-compatible, though.  It also says 
that "Windows Vista compressed icons have also been reported as not 
functioning in the Delphi programming environment".  If I go into 
Graphics.pas and tweak the ReadIcon() function to assume 256x256 when it 
encounters 0x0, then everything works ok and the resulting .bmp is correct.

-- 
Remy Lebeau (TeamB)
0
Remy
7/29/2010 9:40:19 PM
<benoit thonnart> wrote in message news:266598@forums.embarcadero.com...

>                    largeur := bWidth;
>                    if largeur = 0 then largeur := 256;
>                    hauteur := bHeight;
>                    if hauteur = 0 then hauteur := 256;

What happens if the icon really is 0x0?  Is there something else that can be 
looked at to make sure the icon really is not empty before assuming its 
dimensions?

--
Remy Lebeau (TeamB)
0
Remy
7/29/2010 9:41:54 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> <benoit thonnart> wrote in message news:266598@forums.embarcadero.com...
> 
> >                    largeur := bWidth;
> >                    if largeur = 0 then largeur := 256;
> >                    hauteur := bHeight;
> >                    if hauteur = 0 then hauteur := 256;
> 
> What happens if the icon really is 0x0?  Is there something else that can be 
> looked at to make sure the icon really is not empty before assuming its 
> dimensions?
> 
> --
> Remy Lebeau (TeamB)

In french, we say "c'est chercher la petite bête". You can add a test on *dwBytesInRes*.
--
http://www.codeppc.com/telechargements/themegence/themegence.htm
http://www.codeppc.com/telechargements/msceinf/msceinf.htm
0
benoit
7/29/2010 9:48:50 PM
I have posted in the Attachments a program I wrote few years ago, recompiled with Delphi 2007 which allows to handle 256x256 icons (Vista and upper).

1) You can extract icons from icofile, icl (icon library), exe and dll
2) You can see all icons with all resolutions (scrolling for each and diaporama).
3) You can change background to see icons.
4) You can zoom icons for preview (except 256x256).
5) You can extract to an icofile all or selected icons.
6) You can differentiate 256x256 icons with XP or Vista style.

Sorry, it is in french...

See Attachments : https://forums.embarcadero.com/thread.jspa?threadID=40772&stqc=true

--
http://www.codeppc.com/telechargements/themegence/themegence.htm
http://www.codeppc.com/telechargements/msceinf/msceinf.htm
0
benoit
7/29/2010 11:21:53 PM
The program works with the icon posted in Attachments by Eric Holzer. It shows the 3 icons (256x256) in the icofile :
1) the icon with 16 colors.
2) the icon with 256 colors in XP style.
3) the icon with 256 colors in Vista style.
--
http://www.codeppc.com/telechargements/themegence/themegence.htm
http://www.codeppc.com/telechargements/msceinf/msceinf.htm
0
benoit
7/29/2010 11:37:08 PM
The program comes from older Delphi version, so I have forgotten to adapt to 2007 with this : Application.MainFormOnTaskbar := True;
On the previous, icon is shown twice.
Another version is now in Attachments with the update. (https://forums.embarcadero.com/thread.jspa?messageID=264292#264292)
--
http://www.codeppc.com/telechargements/themegence/themegence.htm
http://www.codeppc.com/telechargements/msceinf/msceinf.htm
0
benoit
7/31/2010 10:20:32 AM
Reply:

Similar Artilces:

Icon example for "How to convert 256x256 ICO file to BMP in Delphi 2010? "
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_40524.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" Hello Remy, it is sample icon for previewing purposes only. I have found the icon on virtuallnk dot com. Regards Eric --JivePart=_40524.zeB8CwDOH5aMJzMl Content-Type: application/zip; name="Icon256.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="Icon256.zip" UEsDBBQAAAAIAMRhOTT2vb9vqlICAKbJCwA...

Delphi 2010: how to convert .idl files to .TLB files?
Delphi 2010 ships many IDL files under the folder Embarcadero\RAD Studio\7.0\include\idl I searched the online help, but found no clue how to convert .IDL into the .TLB format, so that I can import the type library. I tried gentlb.exe, but it didn't work. Matt Hall Hi Matt, > I searched the online help, but found no clue how to convert .IDL into the .TLB format, so that I can import the type library. Since Delphi 2009, the Type Library doesn't work with TLB files anymore, but instead with .ridl files (Reduced IDL files). You can also find some imported typ...

Delphi 2010: how to convert .idl files to .TLB files? #2
Delphi 2010 contains many idl files in the \include\idl folder. How can we import these files into an application? In RAD Studio, each .idl file has an associated .h file in the /include folder. So C++ Builder users can import these type libraries. There must be a way for the Delphi users to do the same. But how??????? Unfortunately the Help files don't provide any clue! Can you help?? {quote:title=lcd877 lcd877 wrote:} Delphi 2010 contains many idl files in the \include\idl folder. How can we import these files into an application? In RAD Studio, each .idl file has an ...

Delphi 2010
*Upgrading from Delphi 2007 to Delphi 2010* (as of February 1, 2010) I bought a new computer in December and decided to upgrade from Delphi 2007 to Delphi 2010. Here are some lessons learned related to the Delphi upgrade, which I hope will make a similar transition easier for others. I still have an insurmountable problem with the speed of the IDE (#13 below). As background, my old system had 3 GB of RAM, 40GB of unused disk, a 3.8 GHz CPU, and ran under Windows XP. My new system has 12 GB of RAM, 770GB of unused disk, a quad core 2.67 GHz CPU, and runs under Win7 Home Edition. ...

Delphi XE / Delphi 2010
Hello! I noticed that Embarcadero® Delphi® 2010 Version is not on the list of products on Embarcadero page. Or is it still possible to buy it? Will RAD Studio XE compile programs written in Delphi 2010 without problems.? Thanks. Am 13.09.2010 09:04, schrieb Petra Nemec: > Will RAD Studio XE compile programs written in Delphi 2010 without problems.? As always you will probably have to recreate the projects as the import is still a bit -- special. Christian Hello! Does anybody know if it is still possible to get a Delphi2010 trial version (if yes where)? ...

from delphi 6 to delphi 2010
Hi. It is possible, with component RX, dxforumlibrary, InfoPower3000Pro, StringAlignGrid. Accepts communication BDE. Thank by comments. excequiel arostica wrote: >Hi. > It is possible, with component RX, dxforumlibrary, >InfoPower3000Pro, StringAlignGrid. Accepts communication BDE. > >Thank by comments. Rx is dead and sources are taken over by jcl/jvcl. I dont know about the rest of the components and i have no experiences with bde over the last 9 years. excequiel arostica wrote: > Hi. > It is possible, with component RX, dxforumlibrary,...

Price of upgrade from Delphi 2010 Professional to Delphi 2010 Enterprise?
It's weird, but I could not find the answer on so simple question not in Embarcadero Shop, neither by the forum search. For example, the shop info about Enterprise upgrade says: The Upgrade product is available to registered owners of 2006-2009 versions, blah-blah... So, if I'm Delphi 2010 Professional user, I even not eligible for upgrade? I have to buy a new version of Enterprise??? But if I'm Delphi 2006 Professional user, I can upgrade. Please clarify this nonsense for me. Exact question is in the subject. Thanks! Hi Dmitri, > It's weird, but I could not...

Migrate from Delphi 2007 to Delphi 2010
Hi All, Thanks in advance for your help. Below is my query, Currently I am using Delphi 2007 and i want to migrate to Delphi 2010. 1. What all things i need to take care while doing this? 2. What all third party components will get impacted? 3. Any known issues in Delphi 2010 which might impact the cause? 4. Any changes in database operation required as i am using Oracle? Hope I have post this query under correct category. If not sorry for the trouble and could you please suggest me the correct category for this? Looking forward for your response. Have a great day. Th...

Delphi 2010 professional to Delphi XE3
Hello, Sorry for this is not right place to ask this question: I have Delphi 2010 professional version, I like to upgrade to Delphi XE3 Am eligible to upgrade or no not? I like answer from Delphi sales team. I couldn’t find email to ask them. Thanks Mike Thomas <> wrote in news:506459@forums.embarcadero.com: > Hello, > > Sorry for this is not right place to ask this question: > I have Delphi 2010 professional version, I like to upgrade to Delphi > XE3 Am eligible to upgrade or no not? I like answer from Delphi > sales team. I couldn’t find emai...

Converting from Delphi 2005 to Delphi XE5
I have developed a number of Windows applications in Delphi 2005. I recently purchased Delphi XE5. I have started by trying to compile an existing 2005 application. I am getting a 7 errors about FMXTeeEditor. [dcc32 Error] E1026 File not found: 'FMXTee.Editor.Brush.fmx' Not able to find a solution to this. Any help greatly appreciated. Did you open every form before compiling? The old forms get updated with new properties when they are opened. I would make a copy of the old project before doing any of this. maybe you have links to the older tchart files....i.e its not usi...

converting delphi code to delphi .NET
Hi,I'm looking at converting quite a bit of old delphi code to delphi .NET .  I'm wondering can it be converted to VB.NET for certain ?  Or perhaps there are some unsupported functions etc in delphi and I should keep the code delphi ?  There are about 10,000 lines of code.   Anyone brave enough to take an estimate on how long it would take to convert 10,000 lines ?is going from delphi to delphi.NET smooth ?   Would going to another language cause complications ?Thanks! mike123   Mike123,   Sorry I can not help, however, I have the s...

delphi 2006 code in delphi 2010
hello, is there any option to make delphi 2006 code work in delphi 2010? something like in java IDEs where you can define the code level you like to use? the problem is, that i made a project with 2006 and sent it to my customer. they got 2010 and it compiles fine, but it just doesn't work. it deals with en-/decryption of text, we assumed, that it has something to do with ansi vs. unicode strings... but we cant find the exact position where the error occurs. i am a bit dissapointed, because everywhere i read that the new IDE will always be downwards compatible and so on.. but in ...

Using Delphi 7 and Delphi 2010
I had a project in Delphi 7. I worked on it in Delphi 2010. When I try to open the .dpr again in Delphi 7, the IDE toolbar widens across both monitors, and Delphi 7 locks up. It appears that Delphi 2010 modifies the .dpr in a way that makes Delphi 7 unable to open it again. All my forms & units appear to open fine in D7 after D2010, except for the warnings on the ExplicitHeight and ExplicitWidth properties being missing... I can easily recreate the .dpr, but is this expected behavior? Thanks. Tom Field wrote: > I had a project in Delphi 7. > > I worked o...

Delphi 2010 w Delphi 2007
I have D2007 installed on my laptop (XP sp3 running on dual core Athlon). Can I install D2010 on this machine without it affecting D2007? Will D2010 affect D2007 in any way? Thanks, Randall Carpenter > {quote:title=Randall Carpenter wrote:}{quote} > I have D2007 installed on my laptop (XP sp3 running on dual core Athlon). > Can I install D2010 on this machine without it affecting D2007? Will D2010 > affect D2007 in any way? Won't hurt a thing. I have D7, RAD Studio 2007, RAD Studio 2009, and RAD Studio 2010 all on my desktop system and they coexist fine. Jus...

Web resources about - How to convert 256x256 ICO file to BMP in Delphi 2010? - embarcadero.delphi.nativeapi

File:Convert to SVG and move to Commons.svg - Wikipedia, the free encyclopedia
As a courtesy (but not a requirement), please e-mail me or leave a note on my talk page if you use this image outside of Wikipedia. Thanks! As ...

Facebook Co-Founder Dustin Moskovitz Sells 450K Shares, Converts 7M More
The great Facebook stock sale frenzy continues on with a report that Co-Founder Dustin Moskovitz unloaded 450,000 shares in the social network ...

Facebook Announces “App2User” Liquidity Program for Merchants to Convert Rewards Points into Credits
... for Credits, just announced a new Credits program called “App2User,” designed to enable merchants and loyalty program operators to convert their ...

How to Convert Leads Into Buying Customers - The 9 Step Sales Process EVERYONE Should Use
... School of Business in Toronto on the topics of Sales and Entrepreneurship. I shared with them the sales process that I find How to Convert Leads ...

Bitcoin : Should I convert my savings to Bitcoin?
Answer (1 of 7): You should think of this question as "Should I invest all my savings in Bitcoin?", and not "Should I have my savings denominated ...

Convertizo 2 - Convert Units and Currency in Style on the App Store on iTunes
Get Convertizo 2 - Convert Units and Currency in Style on the App Store. See screenshots and ratings, and read customer reviews.

Catholics should not convert Jews, says Vatican, in push against anti-Semitism
... 50 years since the Vatican's repudiation of the concept of Jewish guilt for Jesus' death.  Vatican City: Catholics should not try to convert ...

Opinion: These 5 things made me a happy iPad Pro convert
... like I needed a bigger device. But after three weeks with my iPad Pro, several things have changed my mind, and I’m officially a happy convert ...

$100 device converts all your film to digital photos
... still on film negatives. Today, we've got the perfect Amazon Cyber Week deal for you: A Wolverine F2D Mighty 20MP 7-in-1 Film to Digital Converter ...

"ISIS 'ranks' the women, considering foreign women and converts to be especially 'valuable.' "
"According to French journalist Anna Erelle’s recent exposé , ISIS foreign fighters prefer foreign women and converts because the jihadists find ...

Resources last updated: 12/22/2015 12:15:20 AM