procedure TFormBarcode.printbmp(str : string);
var GRect : TRect;
    IRatioDif : real;
begin
    {First calculate the ration of the height to width of bitmap}
    IRatioDif := Image1.Picture.Height / Image1.Picture.Width;
    {Then get the various sizes of the printer canvas}
    GRect.Top := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
    GRect.Left := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
    GRect.Right := Printer.PageWidth - GRect.Left;
    GRect.Bottom := trunc(Printer.PageHeight * IRatioDif) - GRect.Top;
    image1.Picture.LoadFromFile('c:\'+str);
    with Printer do    begin
        BeginDoc;
        grect.Top := 0;//这些地方修改打印的范围
        grect.Left := 0;
        grect.Right := trunc(image1.Width * 3) ;
        grect.Bottom := trunc(image1.Height * 3);
        Canvas.StretchDraw(GRect, Image1.Picture.Graphic);
        EndDoc;
    end;end;