Print Bitmap/ru: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Print Bitmap/ru
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Как отправить изображение на принтер | |
| 2 | + | ||
| 3 | + | ``` pascal | |
| 4 | + | // uses Printers; // необходимо подключить модуль | |
| 5 | + | var | |
| 6 | + | Scale :LongInt; | |
| 7 | + | begin | |
| 8 | + | with Printer do | |
| 9 | + | begin | |
| 10 | + | BeginDoc; | |
| 11 | + | Scale := Min( | |
| 12 | + | Printer.PageWidth div Image1.Picture.Bitmap.Width, | |
| 13 | + | Printer.PageHeight div Image1.Picture.Bitmap.Height); | |
| 14 | + | ||
| 15 | + | Printer.Canvas.StretchDraw( | |
| 16 | + | Rect(0, 0, Image1.Picture.Bitmap.Width*Scale, Image1.Picture.Bitmap.Height*Scale), | |
| 17 | + | Image1.Picture.Bitmap); | |
| 18 | + | ||
| 19 | + | EndDoc; | |
| 20 | + | end; | |
| 21 | + | end; | |
| 22 | + | ``` | |
| 23 | + | ||
| 24 | + | \ | |
| 25 | + | **Печать jpeg картинки с масштабированием через Bitmap на лист А4** | |
| 26 | + | ||
| 27 | + | ``` pascal | |
| 28 | + | // uses Printers; // необходимо подключить модуль | |
| 29 | + | procedure PrintImage(Image: TImage); | |
| 30 | + | var | |
| 31 | + | TempImageBMP: Graphics.TBitmap; | |
| 32 | + | TempImageJPEG: TImage; | |
| 33 | + | ScaleX, ScaleY: Double; | |
| 34 | + | RectLeft,RectTop,RectRight,RectBottom: Integer; | |
| 35 | + | begin | |
| 36 | + | ||
| 37 | + | TempImageBMP := Graphics.TBitmap.Create; | |
| 38 | + | TempImageBMP.Assign(Image.Picture.Graphic); | |
| 39 | + | TempImageJPEG := TImage.Create(Self); | |
| 40 | + | TempImageJPEG.Picture.Bitmap := TempImageBMP; | |
| 41 | + | ||
| 42 | + | Printer.BeginDoc; | |
| 43 | + | // Расчет соотношение сторон | |
| 44 | + | ScaleX := Printer.PageWidth / TempImageJPEG.Picture.Bitmap.Width; | |
| 45 | + | ScaleY := Printer.PageHeight / TempImageJPEG.Picture.Bitmap.Height; | |
| 46 | + | ||
| 47 | + | RectLeft:=0; | |
| 48 | + | RectTop:=0; | |
| 49 | + | RectRight := trunc(TempImageJPEG.Picture.Bitmap.Width * scaleX); | |
| 50 | + | RectBottom := trunc(TempImageJPEG.Picture.Bitmap.Height * scaleY); | |
| 51 | + | Printer.Canvas.StretchDraw( | |
| 52 | + | Rect(RectLeft,RectTop,RectRight,RectBottom), | |
| 53 | + | TempImageJPEG.Picture.Bitmap); | |
| 54 | + | Printer.EndDoc; | |
| 55 | + | ||
| 56 | + | TempImageBMP.Free; | |
| 57 | + | TempImageJPEG.Free; | |
| 58 | + | end; | |
| 59 | + | ``` | |
| 60 | + | ||
| 61 | + | --- | |
| 62 | + | *From the Free Pascal wiki, page "Print Bitmap/ru", as it stood on 2020-02-23 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
