よろしくお願いします!
TPrinter で Delphi の写真を実際のサイズの写真で印刷するにはどうすればよいですか? TImage のキャンバスからは良い結果が得られますが、TPrinter キャンバスにペイントすると悪い結果が得られます。
なぜそれが起こるのですか? バグを修正するために何をする必要がありますか?
アップデート
はい、最初の投稿のヒントから質問を見ました。プロジェクトで JCL/JVCL コードを使用できませんが、そこからアイデアを得ました。
一時的な TImage を作成し、プリンターの DPI の係数に従ってその寸法を計算します。
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 <= 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;
そして、TPrinter.Canvas に描画します。
以下の結果を確認できます。
結果は良好ですが、完璧ではありません。
ご覧のとおり、最後の列では、すべての画像が最後まで描かれておらず、紙からはみ出して描かれていない部分もあります。
TImage.Canvas の寸法をプリンターの DPI の係数に従って計算するときに、Trunc を使用して double の整数部分を取得するために発生したと思います。
実験によって、私は値 0.20 を知っています。0.20 は、描画されていない最後の列の画像 (ピクセル単位) の一部です。コードを変更すると、次のようにスケール ファクターが取得されます。
if Printer.Orientation = poPortrait then
scale := GetDeviceCaps(Printer.Handle, LOGPIXELSX) /
Screen.PixelsPerInch - 0.20
else
scale := GetDeviceCaps(Printer.Handle, LOGPIXELSY) /
Screen.PixelsPerInch - 0.20;
私はそれを持っています、私が必要とするもの:
値 0.20 は定数ではなく、すべての PC で変化すると思います。この値を計算する方法は?この問題を解決するには何が必要ですか?