Ver Mensaje Individual
  #2  
Antiguo 14-01-2008
Avatar de salvica
salvica salvica is offline
Miembro
 
Registrado: mar 2004
Ubicación: Albacete (España) ... En un lugar de la Mancha ...
Posts: 304
Reputación: 21
salvica Va por buen camino
Hola mtirado, hace tiempo hice una aplicación para imprimir imágenes que recibía vía FTP (en horizontal o vertical) y las copiaba directamente en el canvas de la impresora, no se si te servirá pero te paso el código.
Código Delphi [-]
{
  al pulsar en el menú IMPRIMIR
}
procedure TWin_Main.mnuImprimir_OnClick(Sender: TObject);
var
//  Impresora      : TPrinter;
  tmpTImage      : TImage;
  tmpGifImagen   : TGIFImage;
  tmpRotateImage : TRotateImage;
  tmpBitMapRotado: TBitMap;
  newArea        : TRect;
  FILE_PRINTER   : string;
  estaHorizontal : boolean;
  estaVertical   : boolean;
begin
{ crear una copia de la imágen original y guardarla como "PRINTER.BMP" }
  FILE_PRINTER   := ExtractFilePath( FILE_COPY ) + 'PRINTER';
  estaHorizontal := false;
  estaVertical   := false;
  tmpGifImagen   := TGIFImage.Create;
  try
    tmpGifImagen.LoadFromFile( FILE_COPY+'.GIF' );
    tmpGifImagen.Frames[0].Bitmap.SaveToFile( FILE_PRINTER+'.BMP' );
    if( tmpGifImagen.Frames[0].Bitmap.Width>tmpGifImagen.Frames[0].Bitmap.Height )
        then estaHorizontal := true
        else estaVertical   := true;
  finally
    tmpGifImagen.Free;
  end;
{ crear un TImage para trabajar con la copia creada }
  tmpTImage      := TImage.Create( nil );
  with tmpTImage do begin
       Visible  := false;
       Parent   := Win_Main;
       AutoSize := true;
       Center   := false;
       Stretch  := false;
  end;
  try
    tmpTImage.Picture.Bitmap.LoadFromFile( FILE_PRINTER+'.BMP' );
    tmpTImage.Refresh;
    if( tmpTImage.Width>tmpTImage.Height ) then begin
        tmpRotateImage := TRotateImage.Create(nil);
        try
          with tmpRotateImage do begin
               UniqueSize := false;
               Picture.LoadFromFile( FILE_PRINTER+'.BMP' );
               Angle := -90;
               RotatedBitmap.SaveToFile(FILE_PRINTER+'.BMP');
          end;
        finally
          tmpRotateImage.Free;
        end;
    end;
  finally
    tmpTImage.Free;
  end;
{ rotar la imágen en "vertical" (si hace falta) }
  {
  if( estaHorizontal and (Printer.PageHeight>Printer.PageWidth) ) or
    ( estaVertical   and (Printer.PageWidth>Printer.PageHeight) ) then begin
      tmpRotateImage := TRotateImage.Create(nil);
      try
        with tmpRotateImage do begin
             UniqueSize := false;
             Picture.LoadFromFile( FILE_PRINTER+'.BMP' );
             if( Picture.Bitmap.Width>Printer.PageWidth ) then begin
                 Angle := -90;
                 RotatedBitmap.SaveToFile(FILE_PRINTER+'.BMP');
             end;
        end;
      finally
        tmpRotateImage.Free;
        Image.Picture.LoadFromFile( FILE_PRINTER+'.BMP' );
      end;
  end;
  }
  tmpBitMapRotado:= TBitMap.Create;
  try
    tmpBitMapRotado.LoadFromFile( FILE_PRINTER+'.BMP' );
    with Printer do begin
         Title := 'MAPA '+ExtractFileName( FILE_COPY )+' correspondiente al '+FechaToCadena( Now, true );
         if( tmpBitMapRotado.Width>tmpBitMapRotado.Height ) then begin
           { orientación horizontal, girar el mapa }
             Orientation := poLandscape;
         end else begin
           { orientación vertical }
             Orientation := poPortrait;
         end;
         with newArea do begin
              Left   := 100;
              Top    := 100;
              Right  := PageWidth  - 200;
              Bottom := PageHeight - 200;
         end;
         BeginDoc;
         Canvas.StretchDraw( newArea, tmpBitMapRotado );
         Canvas.TextOut( 50, 10, Title );
         EndDoc;
    end;
  finally
    tmpBitMapRotado.Free;
  end;
{ eliminar la copia de la imágen original y desactivar el menú "IMPRIMIR" }
  if FileExists( FILE_PRINTER+'.BMP' ) then DeleteFile( FILE_PRINTER+'.BMP' );
  mnuImprimir.Enabled := false;
end;
La imágen podía tener cualquier tamaño. La parte que te interesa está al final, donde ajusto la imagen al tamaño del paper (DIN-A4)

Saludos
salvica
Responder Con Cita