Hi, wäre toll, wenn mir jemand helfen könnte, wo mein Denkfehler liegt...
Ich will mein Bitmap skalieren, falls es größer ist als der Druckbereich. Dafür rechne ich mir die Seitengröße und den nicht bedruckbaren Bereich aus und erhalte dann PrintableAreaX bzw -Y. Falls diese Zahl also größer ist als die Bmp.Width bzw Bmp.Height kann ganz normal gezeichnet werden, ansonsten soll er aber skalieren.
Bei 300 dpi ist noch alles in Ordnung und ich dachte schon alles würde wunderbar funktionieren, jetzt ist mir 600 dpi allerdings mal aufgefallen, dass er garnich in den Else-Teil reingeht, weil PrintableAreaX bzw. -Y immer größer ist als die Bitmaphöhe oder -breite. Das kann teilweise aber dann garnich stimmen, weil er ja im Ausdruck mir die Hälfte des Bildes abschneidet.
Hab ich irgendwo was vergessen? Wäre toll, wenn mir da einer helfen könnte!!! Danke schonmal im Vorraus!
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: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108:
| class function MillimeterPerPixel(MM: Integer): Integer; var PrinterDPI: Integer; begin PrinterDPI := GetDeviceCaps(Printer.Handle, LOGPIXELSY); Result := Round((PrinterDPI / 25.4) * MM); end;
procedure Print; var Bmp: TBitmap; X: Integer; Y: Integer; Rect: TRect; BmpWidth: Integer; BmpHeight: Integer; PageWidth: Integer; PageHeight: Integer; PrintableAreaX: Integer; PrintableAreaY: Integer; Scale: Double; DiffHeight: Integer; DiffWidth: Integer; begin if (PrintDialog.Execute) then begin try Printer.BeginDoc; Printer.Title := 'Treemap';
Bmp := TBitmap.Create; Bmp.LoadFromFile('Bitmap.bmp');
SetMapMode(Printer.Canvas.Handle, MM_LOMETRIC);
BmpWidth := Round(MillimeterPerPixel(Bmp.Width) / 10); BmpHeight := Round(MillimeterPerPixel(Bmp.Height) / 10);
X := Round((GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX) * MillimeterPerPixel(1)) / 10); Y := Round((GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY) * MillimeterPerPixel(1)) / 10);
PageWidth := Round((GetDeviceCaps(Printer.Handle, PHYSICALWIDTH) * MillimeterPerPixel(1))/10); PageHeight := Round((GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT) * MillimeterperPixel(1))/10);
PrintableAreaX := PageWidth - (2*X); PrintableAreaY := PageHeight - (2*Y);
SetWindowOrgEx(Printer.Handle, X, -Y, nil);
Rect.TopLeft := Point(X, -Y);
if ((PrintableAreaX >= BmpWidth + X) and (PrintableAreaY >= BmpHeight + Y)) then Rect.BottomRight := Point(BmpWidth+X, -(BmpHeight+Y)) else if ((PrintableAreaX >= BmpWidth + X) and (PrintableAreaY < BmpHeight + Y)) then begin Rect.BottomRight.Y := PrintableAreaY; Scale := BmpHeight / PrintableAreaY; Rect.BottomRight.X := Round(BmpWidth / Scale); end else if ((PrintableAreaX < BmpWidth + X) and (PrintableAreaY >= BmpHeight + Y)) then begin Rect.BottomRight.X := PrintableAreaX; Scale := BmpWidth / PrintableAreaX; Rect.BottomRight.Y := Round(BmpHeight / Scale); end else if ((PrintableAreaX < BmpWidth + X) and (PrintableAreaY < BmpHeight + Y)) then begin DiffWidth := BmpWidth - PrintableAreaX; DiffHeight := BmpHeight - PrintableAreaY; if(DiffHeight > DiffWidth) then begin Rect.BottomRight.Y := PrintableAreaY; Scale := BmpHeight / PrintableAreaY; Rect.BottomRight.X := Round(BmpWidth / Scale); end else begin Rect.BottomRight.X := PrintableAreaX; Scale := BmpWidth / PrintableAreaX; Rect.BottomRight.Y := Round(BmpHeight / Scale); end; end;
Printer.Canvas.StretchDraw(Rect, Bmp); finally Printer.EndDoc; Bmp.Free; end; end else exit; end; |
Alles Liebe,
daschaos