Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to print images on TPrinter in real size of image?
    primarykey
    data
    text
    <p>Gretings to all!</p> <p>How to print pictures in Delphi on TPrinter, in real sizes of pictures? From canvas of TImage I have good results, but if I paints on TPrinter canvas, I have BAD result, puctures is too small than real size of bitmap. </p> <p>Why that happens What I'm need to do for fix bug? </p> <p><strong>UPDATE</strong></p> <p>Yes, I seen question from the hint in the 1st post. I can't use JCL/JVCL code in my project, but I got idea from it. </p> <p>I create temporary TImage, and calculate dimensions of it in accordance with the factor of printer's DPI:</p> <pre><code>var i, iRow, iCol, // Counter iBorderSize, // Ident from left/top borders iImgDistance, // Ident between images in grid iRows, // Rows Count iColumns, // Colun count iLeft, iTop: Integer; // For calc bmp: TBitmap; bStop, bRowDone, bColDone: Boolean; Img1: TImage; scale: Double; function CalcY: Integer; begin if (iRow = 1) then Result := iBorderSize else Result := iBorderSize + (iImgDistance * (iRow - 1)) + (bmp.Height * (iRow - 1)); end; function CalcX: Integer; begin if (iCol = 1) then Result := iBorderSize else Result := iBorderSize + (iImgDistance * (iCol - 1)) + (bmp.Width * (iCol - 1)); end; begin iBorderSize := StrToInt(BorderSizeEdit.Text); iImgDistance := StrToInt(ImgsDistanceEdit.Text); iRows := StrToInt(RowsCountEdit.Text); iColumns := StrToInt(ColCountEdit.Text); iRow := 1; iCol := 1; iLeft := iBorderSize; iTop := iBorderSize; if Printer.Orientation = poPortrait then scale := GetDeviceCaps(Printer.Handle, LOGPIXELSX) / Screen.PixelsPerInch else scale := GetDeviceCaps(Printer.Handle, LOGPIXELSY) / Screen.PixelsPerInch; bmp := TBitmap.Create; Img1 := TImage.Create(nil); Img1.Height := Trunc(Printer.PageHeight / scale); //Calc canvas size Img1.Width := Trunc(Printer.PageWidth / scale); //Calc canvas size Img1.Canvas.Brush.Color := clWhite; Img1.Canvas.FillRect(Rect(0, 0, Img1.Width, Img1.Height)); try bmp.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Source.bmp'); for i := 1 to 18 do begin if (iRow &lt;= iRows) then begin iTop := CalcY; iLeft := CalcX; Img1.Canvas.Draw(iLeft, iTop, bmp); if not((iRow = iRows) and (iCol = iColumns)) then begin if (iCol = iColumns) then begin Inc(iRow); iCol := 1; end else Inc(iCol); end else begin PrintImage(Img1, 100); iRow := 1; iCol := 1; Img1.Canvas.Brush.Color := clWhite; Img1.Canvas.FillRect(Rect(0, 0, Img1.Width, Img1.Height)); end; end; end; finally FreeAndNil(bmp); FreeAndNil(Img1); end; end; </code></pre> <p>And draw it on TPrinter.Canvas.</p> <p>You can see results below: </p> <p><img src="https://i.stack.imgur.com/YXjGd.png" alt="You can see results below:"></p> <p>Results is good, but not perfect.</p> <p>As you can see, in the last column, all images are drawn not to the end, some part misses off the paper and not drawn.</p> <p>I think it's happens because I use the Trunc to get integer part of double when I'm calculate dimensions of TImage.Canvas in accordance with the factor of printer's DPI.</p> <p>By experiments I know value 0.20. 0.20 is a part of last column images, in pixels, that not drawn. If I change code, that gets scale factor by this:</p> <pre><code> if Printer.Orientation = poPortrait then scale := GetDeviceCaps(Printer.Handle, LOGPIXELSX) / Screen.PixelsPerInch - 0.20 else scale := GetDeviceCaps(Printer.Handle, LOGPIXELSY) / Screen.PixelsPerInch - 0.20; </code></pre> <p>I have that, what I need:</p> <p><img src="https://i.stack.imgur.com/WdnOz.png" alt="I have that, what I need:"></p> <p><strong>I think the value 0.20 isn't a constant and it will change on every PC. How to calculate this value? What need to solve this problem?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload