Gracias por tu tiempo, jconnor82.
Cita:
Empezado por jconnor82
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); 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; 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
[-]
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');
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;
procedure TForm1.Button3Click(Sender: TObject);
var
Ico: TIcon;
begin
Ico := TIcon.Create;
try
ConvertTo32BitImageList(ImageList1);
Ico.LoadFromFile('browser.ico');
Label1.Caption := ('ImageList1.Width: '+IntToStr (ImageList1.Width) + '; Ico.Width: '+IntToStr (Ico.Width));
Label2.Caption := ('ImageList1.Height: '+IntToStr (ImageList1.Height) + '; Ico.Height: '+IntToStr (Ico.Height));
TrayIcon1.Icon := Ico;
ImageList1.AddIcon(TrayIcon1.Icon);
Label3.Caption := ('ImageList1.Width: '+IntToStr (ImageList1.Width) + '; Ico.Width: '+IntToStr (Ico.Width));
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.