Bien antes de nada, creo que le das muchas vueltas, con algo asi creo que obtendriamos el mismo resultado:
Código Delphi
[-]
var
GraphType: TGraphType;
Stream: TMemoryStream;
begin
if dlgOpenPicture.Execute then
with Image1.Picture do
begin
LoadFromFile(dlgOpenPicture.FileName);
if Graphic is TBitmap then GraphType:= gtBitmap else
if Graphic is TIcon then GraphType:= gtIcon else
if Graphic is TMetafile then GraphType:= gtMetafile else
if Graphic is TJPEGImage then GraphType:= gtJpeg;
Stream:= TMemoryStream.Create;
try
Stream.WriteBuffer(GraphType, 1);
Graphic.SaveToStream(Stream);
finally
Stream.Free;
end;
end;
end;
Ahora volvamos al tema de tu pregunta, si lo que quieres es que a la hora de mostrar la imagen esta se ajuste al tamaño del TImage echale un vistzao en la ayuda a las propiedades Stretch y Proportional del TImage que creo pueden darte el efecto que buscas.
Si por el contrario quieres redimensionar la imagen puedes usar alguan de estas funciones que ya describi en un
hilo anterior:
Código Delphi
[-]
procedure Redimensionar(Imagen: TGraphic; Ancho, Alto: Integer);
var
Bitmap: TBitmap;
begin
Bitmap:= TBitmap.Create;
try
Bitmap.Width:= Ancho;
Bitmap.Height:= Alto;
Bitmap.Canvas.StretchDraw(Bitmap.Canvas.ClipRect,Imagen);
Imagen.Assign(Bitmap);
finally
Bitmap.Free;
end;
end;
procedure Proporcional(Imagen: TGraphic; Ancho, Alto: Integer);
var
Bitmap: TBitmap;
begin
Bitmap:= TBitmap.Create;
try
if (Ancho/Imagen.Width) < (Alto/Imagen.Height) then
Alto:= Trunc((Ancho*Imagen.Height)/Imagen.Width)
else
Ancho:= Trunc((Imagen.Width*Alto)/Imagen.Height);
Bitmap.Width:= Ancho;
Bitmap.Height:= Alto;
Bitmap.Canvas.StretchDraw(Bitmap.Canvas.ClipRect,Imagen);
Imagen.Assign(Bitmap);
finally
Bitmap.Free;
end;
end;
Combinando los dos codigos anteirores nos quedaria algo como esto:
Código Delphi
[-]
var
GraphType: TGraphType;
Stream: TMemoryStream;
begin
if dlgOpenPicture.Execute then
with Image1.Picture do
begin
LoadFromFile(dlgOpenPicture.FileName);
Proporcional(Graphic,Image1.Width,Image1.Height);
if Graphic is TBitmap then GraphType:= gtBitmap else
if Graphic is TIcon then GraphType:= gtIcon else
if Graphic is TMetafile then GraphType:= gtMetafile else
if Graphic is TJPEGImage then GraphType:= gtJpeg;
Stream:= TMemoryStream.Create;
try
Stream.WriteBuffer(GraphType, 1);
Graphic.SaveToStream(Stream);
finally
Stream.Free;
end;
end;
end;
Ten en cuenta que este ultimo codigo si modifica el tamaño real de la imagen y la imagen se guardara con el tamaño cambiado