Je dessinerais dans la toile d'image en utilisant lineto fonction, et puis imprimé cela. mais l'imprimante crée une page vide. J'ai utilisé printer.canvas.StretchDraw mais si l'image a été enregistrée puis chargée, l'impression de l'image sera réussie. Quelqu'un connaît la raison?(delphi) imprimer problème d'image
1
A
Répondre
2
Voici ce que j'utilise:
function PrintWrapper(ADrawProc : TDrawProc;
APreview: Boolean;
AWidth, AHeight : longint) : boolean;
var
bmp : Graphics.TBitmap;
PixPerInchX, PixPerInchY : longint;
begin
bmp := Graphics.TBitmap.Create;
try
if APreview then begin
PixPerInchX := GetDeviceCaps(bmp.Canvas.Handle, LOGPIXELSX);
PixPerInchY := GetDeviceCaps(bmp.Canvas.Handle, LOGPIXELSY);
bmp.Width := PixPerInchX * AWidth;
bmp.Height := PixPerInchY * AHeight;
bmp.Canvas.Brush.Color := clWhite;
bmp.Canvas.FillRect(Rect(0,0,bmp.Width,bmp.Height));
ADrawProc(bmp.Canvas,AWidth,AHeight);
result := (not APreview) or TFormImagePrintPreview.PrintNow(bmp);
if not result then
exit;
end;
Printer.Orientation := poLandscape;
Printer.BeginDoc;
try
ADrawProc(Printer.Canvas,AValues,AWidth,AHeight);
finally
Printer.EndDoc;
end;
result := true;
finally
FreeAndNil(bmp);
end;
end;
Où DrawProc est:
type
TDrawProc = procedure(ACanvas : TCanvas;
Width, Height : longint);
Et l'aperçu de l'image est la suivante:
unit formImagePreviewDef;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TformImagePrintPreview = class(TForm)
pnBottom: TPanel;
btPrint: TButton;
btCancel: TButton;
imgMain: TImage;
lbNotes: TLabel;
procedure btPrintClick(Sender: TObject);
procedure btCancelClick(Sender: TObject);
public
procedure Init(AGraphic : TGraphic; ANotes : string = '');
class function PrintNow(AGraphic : TGraphic; ANotes : string = '') : boolean;
end;
implementation
{$R *.dfm}
{ TformImagePrintPreview }
procedure TformImagePrintPreview.btCancelClick(Sender: TObject);
begin
Close;
ModalResult := mrCancel;
end;
procedure TformImagePrintPreview.btPrintClick(Sender: TObject);
begin
Close;
ModalResult := mrOk;
end;
procedure TformImagePrintPreview.Init(AGraphic: TGraphic; ANotes : string = '');
const
MAXSIZE = 600;
begin
lbNotes.caption := ANotes;
imgMain.Picture.Assign(AGraphic);
if AGraphic.Height > AGraphic.Width then begin
ClientWidth := trunc(MAXSIZE * AGraphic.Width/AGraphic.Height);
ClientHeight := MAXSIZE + pnBottom.Height;
end else begin
Width := MAXSIZE;
Height := trunc(MAXSIZE * AGraphic.Height/ AGraphic.Width)+pnBottom.Height;
end;
end;
class function TformImagePrintPreview.PrintNow(AGraphic: TGraphic; ANotes : string = ''): boolean;
var
form : TformImagePrintPreview;
begin
form := TformImagePrintPreview.Create(nil);
try
form.Init(AGraphic,ANotes);
result := form.ShowModal = mrOk;
finally
FreeAndNil(form);
end;
end;
end.
1
Peut-être vous ignorez le fait que la page d'impression a résolution différente d'une page d'écran.
Les points que vous voulez dessiner sur la toile d'impression doivent être multipliées par un facteur, comme Zartog utilise dans son exemple:
PixPerInchX := GetDeviceCaps(bmp.Canvas.Handle, LOGPIXELSX);
PixPerInchY := GetDeviceCaps(bmp.Canvas.Handle, LOGPIXELSY);
bmp.Width := PixPerInchX * AWidth;
bmp.Height := PixPerInchY * AHeight;
Voici un tutoriel simple sur la façon d'imprimer: Printing Directly from Delphi
Questions connexes
- 1. Delphi SearchText Problème
- 2. Problème de sécurité Delphi et Microsoft ATL
- 3. Delphi 2009 problème de compilation de génériques
- 4. postthreadmessage et peekmessage problème dans delphi 2006
- 5. Delphi VirtualTreeview.OnAfterItemPaint problème lors du défilement?
- 6. Problème des services Web Delphi 2005
- 7. Imprimer datatable
- 8. Problème de rafraîchissement de composant personnalisé avec Delphi
- 9. Delphi - MadCrypt - Problème de cryptage et de décryptage d'une chaîne
- 10. Delphi, détection de charset ([Uni] SynEdit) - Problème Utf8Decode
- 11. problème de programmation avec des fichiers xml dans delphi
- 12. service Web Delphi Importateur et caractère NonAscii Problème
- 13. Problème RTTI Delphi: GetPropInfo renvoie zéro avec {$ METHODINFO ON}?
- 14. FitNesse pour Delphi 2006/Delphi 2007/Delphi 2009
- 15. Imprimer certains onglets
- 16. Imprimer les modifications DOM
- 17. Imprimer avec Javascript?
- 18. Imprimer FixedDocument par programme
- 19. imprimer un jpg
- 20. Comment imprimer WPF multipage?
- 21. Comment imprimer un chèque?
- 22. XPS Document Imprimer Carrelage
- 23. Imprimer Feuille Excel incorporée
- 24. Comment imprimer dataGridview
- 25. Imprimer Multipage dans WPF
- 26. preg_match_all imprimer * tous les * matchs
- 27. Options pour imprimer une étiquette avec un code à barres?
- 28. "Les bases de Delphi" dans Delphi 2009
- 29. Delphi à java, savon delphi, sms envoyer
- 30. delphi dans vista
Pourriez-vous montrer le code qui est impliqué? C'est plus facile d'aider si nous voyons ce que vous faites. – Argalatyr