Ver Mensaje Individual
  #8  
Antiguo 20-04-2009
Chandra_ Chandra_ is offline
Miembro
 
Registrado: may 2008
Posts: 50
Reputación: 17
Chandra_ Va por buen camino
Gracias por tu tiempo, jconnor82.

Cita:
Empezado por jconnor82 Ver Mensaje
No lo he probado pero antes de cargar el icono no se tendria q dar las dimensiones?.
Pues tampoco funciona. A continuación tienes el código con las líneas que propones y... sigue dando el mismo mensaje de error:

Código:
Proyect Proyect1.exe raised exception class EInvalidOperation with message 'Invalid Image Size'
Código Delphi [-]
procedure TForm1.Button2Click(Sender: TObject);
var
  Ico: TIcon;
begin
  Ico := TIcon.Create;
  try
   ConvertTo32BitImageList(ImageList1);
   Ico.Width  := ImageList1.Width;
   Ico.Height := ImageList1.Height;
   Ico.LoadFromFile('icono48x48.ico');
   ImageList1.AddIcon(Ico);   // <--- aquí salta de nuevo el error
  finally
    Ico.Free;
  end;
end;

Lo curioso es que lo siguiente no falla, pero, aunque el Height y el Width del ImageList los pongo en tiempo de diseño en 48 (lo juro), el icono final lo reconvierte a 32x32 y sin canal alfa

Código Delphi [-]
procedure TForm1.Button2Click(Sender: TObject);
var
  Ico: TIcon;
begin
  Ico := TIcon.Create;
  try
   ConvertTo32BitImageList(ImageList1);
   Ico.Width  := 48;
   Ico.Height := 48; //esto se lo pasa Delphi por las narices: el Ico sigue a 32x32
   Ico.LoadFromFile('icono48x48.ico');

     Label1.Caption := ('ImageList1.Width: '+IntToStr (ImageList1.Width) + '; Ico.Width: '+IntToStr (Ico.Width));
   ImageList1.Width := Ico.Width;
     Label2.Caption := ('ImageList1.Width: '+IntToStr (ImageList1.Width) + '; Ico.Width: '+IntToStr (Ico.Width));

     Label3.Caption := ('ImageList1.Height: '+IntToStr (ImageList1.Height) + '; Ico.Height: '+IntToStr (Ico.Height));
   ImageList1.Height := Ico.Height;
     Label4.Caption := ('ImageList1.Height: '+IntToStr (ImageList1.Height) + '; Ico.Height: '+IntToStr (Ico.Height));

   ImageList1.AddIcon(Ico);
  finally
    Ico.Free;
  end;
end;

También da error si el ImageList no está vacío, y está ya precargado con un icono 48x48 (es decir, si por co**nes el ImageList está a 48x48).

¿Por qué sí se puede hacer si carcas el icono a través de un TrayIcon? No sé... misterios insondables de Delphi

CONCLUSIÓN: Los TIcon, según les pilla, no aceptam iconos de más de 32x32. Es decir, si le van a pasar el icono a un TrayIcon, se lo pasan de 48x48 sin despeinarse; si el que recibe es un ImageList... se vuelven tontos y dicen que el icono es de 32x32

Se pueden "cazar" fácilmente las gamberradas de Delphi en el siguiente código con 4 TLabel:

Código Delphi [-]
//Funciona, pero dibuja iconos 32x32 sin canal alfa
procedure TForm1.Button2Click(Sender: TObject);
var
  Ico: TIcon;
begin
  Ico := TIcon.Create;
  try
   ConvertTo32BitImageList(ImageList1);
   Ico.Width  := 48;
   Ico.Height := 48;
   Ico.LoadFromFile('browser.ico');

     //salida de label1: ImageList1.Width: 48; Ico.Width: 32
     Label1.Caption := ('ImageList1.Width: '+IntToStr (ImageList1.Width) + '; Ico.Width: '+IntToStr (Ico.Width));
   ImageList1.Width := Ico.Width;
     //salida de label2: ImageList1.Width: 32; Ico.Width: 32
     Label2.Caption := ('ImageList1.Width: '+IntToStr (ImageList1.Width) + '; Ico.Width: '+IntToStr (Ico.Width));

     //salida de label3: ImageList1.Height: 48; Ico.Height: 32
     Label3.Caption := ('ImageList1.Height: '+IntToStr (ImageList1.Height) + '; Ico.Height: '+IntToStr (Ico.Height));
   ImageList1.Height := Ico.Height;
     //salida de label4: ImageList1.Height: 32; Ico.Height: 32
     Label4.Caption := ('ImageList1.Height: '+IntToStr (ImageList1.Height) + '; Ico.Height: '+IntToStr (Ico.Height));

   ImageList1.AddIcon(Ico);
  finally
    Ico.Free;
  end;
end;

//funciona
procedure TForm1.Button3Click(Sender: TObject);
var
  Ico: TIcon;
begin
  Ico := TIcon.Create;
  try
   ConvertTo32BitImageList(ImageList1);
   Ico.LoadFromFile('browser.ico');
     //salida de label1: ImageList1.Width: 48; Ico.Width: 32
     Label1.Caption := ('ImageList1.Width: '+IntToStr (ImageList1.Width) + '; Ico.Width: '+IntToStr (Ico.Width));
     //salida de label2: ImageList1.Height: 48; Ico.Height: 32
     Label2.Caption := ('ImageList1.Height: '+IntToStr (ImageList1.Height) + '; Ico.Height: '+IntToStr (Ico.Height));
   TrayIcon1.Icon := Ico;
   ImageList1.AddIcon(TrayIcon1.Icon);
      //salida de label3: ImageList1.Width: 48; Ico.Width: 48   ¡¡¡Sorpresa!!! ha cambiado el tamaño
      Label3.Caption := ('ImageList1.Width: '+IntToStr (ImageList1.Width) + '; Ico.Width: '+IntToStr (Ico.Width));
     //salida de label4: ImageList1.Height: 48; Ico.Height: 48   ¡¡¡Sorpresa!!! ha cambiado el tamaño
     Label4.Caption := ('ImageList1.Height: '+IntToStr (ImageList1.Height) + '; Ico.Height: '+IntToStr (Ico.Height));
  finally
    Ico.Free;
  end;
end;

Os animo a hacer las pruebas y vereis qué "divertido" puede llegar a ser Delphi...

Por cierto, jconnor82, voy a probar la unit ahora, a ver qué tal me va. Luego te cuento. Ah, y muchas gracias.
Responder Con Cita