Autor Beitrag
mk2
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 72

WIN 2000
D4 Prof
BeitragVerfasst: Fr 28.03.03 18:21 
Hi,

Ich hab ein Riesenproblem mit dem Drucken in meinem Programm.
Ich benutze die copyrect-Methode um die canvas meiner form direkt auf den Drucker zu kopieren. Druckt auch im Prinzip wunderbar, aber nicht auf allen Druckern in unserem Institut. Ich hab jetzt insgesamt 6 drucker ausprobiert: 4 waren unterschiedliche hp deskjet (959,970,..) bei denen alles funktionierte. Dann sind da aber noch 2 Laserdrucker von HP und Brother, die immer nur ein weißes Blatt bei meinem Programm ausspucken. Ansonsten sind die laserdrucker voll funktionsfähig - pdfs docs - geht alles.

Warum macht das nen Unterschied was für nen Drucker ich benutze?
Ist das Delphi nicht egal? Sollte sich der Windows Druckertreiber nicht darum kümmern, dass jeder Drucker richtig angesprochen wird?

Ich bin echt verzweifelt und brauche dringend Hilfe

Der Code zum Drucken sieht(etwas vereinfacht) so aus:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
if Printdialog1.Execute then
  begin
     printer.BeginDoc;
     form1.Canvas.Refresh;
     application.ProcessMessages;

     // scale
     w:=form1.Width; h:=form1.height;
      wp:=printer.PageWidth - 20;
      hp:=wp*h div w;

     // copy canvas to printer
     Printer.Canvas.CopyRect(
     Rect(10,50,wp,hp),
     form1.Canvas,
     Rect(page1.Left,page1.top,w+page1.Left,  
            h+page1.top));

     printer.EndDoc;
  end;


MfG mk2


Moderiert von user profile icontommie-lie: Titel geändert
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Fr 28.03.03 20:17 
Hi,

benutz mal diese procedure hier zum drucken, damit sollte dann alles gehen.. (ich hing auch ewig lange vor dem Problem... :wink: )

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
PROCEDURE PrintBitmap(Canvas:  TCanvas; DestRect:  TRect;  Bitmap:  TBitmap);
  VAR
    BitmapHeader:  pBitmapInfo;
    BitmapImage :  POINTER;
    HeaderSize  :  DWORD;    // Use DWORD for D3-D5 compatibility
    ImageSize   :  DWORD;
BEGIN
  GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
  GetMem(BitmapHeader, HeaderSize);
  GetMem(BitmapImage,  ImageSize);
  TRY
    GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);
    StretchDIBits(Canvas.Handle,
                  DestRect.Left, DestRect.Top,     // Destination Origin
                  DestRect.Right  - DestRect.Left, // Destination Width
                  DestRect.Bottom - DestRect.Top,  // Destination Height
                  0, 0,                            // Source Origin
                  Bitmap.Width, Bitmap.Height,     // Source Width & Height
                  BitmapImage,
                  TBitmapInfo(BitmapHeader^),
                  DIB_RGB_COLORS,
                  SRCCOPY)
  FINALLY
    FreeMem(BitmapHeader);
    FreeMem(BitmapImage)
  END
END {PrintBitmap};


Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
mk2 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 72

WIN 2000
D4 Prof
BeitragVerfasst: Mo 31.03.03 08:42 
danke erstmal aya,

aber wie genau rufe ich die methode in meinem fall auf?
Wenn ichs richtig verstehe übergebe ich als Canvas Parameter Printer.canvas und als DestRect den Bereich der Printer-Canvas auf den kopiert werden soll. Aber wie wandele ich meine Form1.Canvas in ein Bitmap um (welches ja der 3. Parameter der Prozedur sein müßte) ?

MfG mk2
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Mo 31.03.03 12:04 
Hi,

achso... du willst dein Form ausdrucken?? :oops:
mh... Canvas -> Bitmap...

Erstellst dir ein Bitmap und machst das so groß wie dein Form :)
Dann einfach mit Bitmap.CopyRect(...) den Canvas vom Form draufkopieren, und fertig ;)

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
mk2 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 72

WIN 2000
D4 Prof
BeitragVerfasst: Mo 31.03.03 13:02 
vielen vielen Dank,

Ich kanns kaum glauben aber mit dieser Prozedur druckt das Programm jetzt wirklich auf allen Druckern. Ich finds zwar sehr mysteriös, dass man copyrect nicht direkt auf Printer.Canvas anwenden kann, aber was solls - Hauptsache es läuft.

MfG micha