Ver Mensaje Individual
  #3  
Antiguo 05-06-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
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);
        // Aqui lo de la base de datos
        {
        if (tblPeliculas.State <> dsEdit) and (tblPeliculas.State <> dsInsert) then
          tblPeliculas.Edit;
        Stream.Position := 0;
        TBlobField(tblPeliculas.FieldByName('Imagen')).LoadFromStream(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 [-]
// Esta cambia el alto y ancho, estirando la imagen si es necesario
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;

// Esta otra mantiene la relacion entre alto y ancho
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);
      // Aqui puedes usar Proporcional o Redimensionar 
     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);
        // Aqui lo de la base de datos
        {
        if (tblPeliculas.State <> dsEdit) and (tblPeliculas.State <> dsInsert) then
          tblPeliculas.Edit;
        Stream.Position := 0;
        TBlobField(tblPeliculas.FieldByName('Imagen')).LoadFromStream(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
Responder Con Cita