Home
Top.Mail.Ru Yandeks.Metrika
Forum: "Main";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Down

Problem with the size of the image when printing Find similar branches


Oleg Gashev   (2001-12-15 11:14) [0]

It is impossible to print Image with exact dimensions. It still doesn't print correctly.
I do so. Find Bitmapa dimensions in inch:
sx, sy: real; ABitmap: = Image1.Picture.Bitmap; sx: = ABitmap.Width / GetDeviceCaps (image1.canvas.handle, LOGPIXELSX); sy: = ABitmap.Height / GetDeviceCaps (image1.canvas.handle, LOGPIXELSY);

Now I find the dimensions in pixels on the printer for printing:
relwidth: = trunc (GetDeviceCaps (Printer.canvas.handle, LOGPIXELSX) * sx); relheight: = trunc (GetDeviceCaps (Printer.canvas.handle, LOGPIXELSY) * sy);

Print:
Printer.BeginDoc; DrawImage (Printer.Canvas, Rect (0, 0, relWidth, relHeight), ABitmap); Printer.EndDoc;

DrawImage:
procedure DrawImage (Canvas: TCanvas; DestRect: TRect; ABitmap: TBitmap); var Header, Bits: Pointer; HeaderSize: Cardinal; BitsSize: Cardinal; begin GetDIBSizes (ABitmap.Handle, HeaderSize, BitsSize); Header: = AllocMem (HeaderSize); Bits: = AllocMem (BitsSize); try GetDIB (ABitmap.Handle, ABitmap.Palette, Header ^, Bits ^); StretchDIBits (Canvas.Handle, DestRect.Left, DestRect.Top, DestRect.Right, DestRect.Bottom, 0, 0, ABitmap.Width, ABitmap.Height, Bits, TBitmapInfo (Header ^), DIB_RGB_COLORS, SRCC; finally FreeMem (Header, HeaderSize); FreeMem (Bits, BitsSize); end; end;

All this prints with the wrong size. Where is the mistake?

Regards, Oleg.



MrBeer   (2001-12-16 21:27) [1]

// Print bitmap X x Y millimeters size procedure PrintBM (B: TBitmap; x_mm, y_mm: double); var resx, resy: double; begin resx: = Printer.PageWidth / GetDeviceCaps (Printer.Handle, LOGPIXELSX); resy: = Printer.PageHeight / GetDeviceCaps (Printer.Handle, LOGPIXELSY); Printer.Canvas.StretchDraw (Rect (0,0, round (x_mm * resx), round (y_mm * resy)), B); end; // Print bitmap X x Y inch size procedure PrintBMInch (B: TBitmap; x_inch, y_inch: double); begin PrintBM (B, x_inch * 2.54, y_inch * 2.54); end;



MrBeer   (2001-12-16 21:40) [2]

procedure PrintSameSize (B: TBitmap); var scalex, scaley: double; begin scalex: = GetDeviceCaps (Printer.Handle, LOGPIXELSX) / GetDeviceCaps (B.Canvas.Handle, LOGPIXELSX); scaley: = GetDeviceCaps (Printer.Handle, LOGPIXELSY) / GetDeviceCaps (B.Canvas.Handle, LOGPIXELSY); Printer.Canvas.StretchDraw (Rect (0,0, round (B.Width * scalex), round (B.Height * scaley)), B); end;



MrBeer   (2001-12-16 21:48) [3]

A esli tak napisatj?
// ....
scalex: = GetDeviceCaps (Printer.Handle, LOGPIXELSX) / GetDeviceCaps (GetDC (0), LOGPIXELSX); scaley: = GetDeviceCaps (Printer.Handle, LOGPIXELSY) / GetDeviceCaps (GetDC (0), LOGPIXELSY);



Pages: 1 whole branch

Forum: "Main";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Top





Memory: 0.55 MB
Time: 0.022 c
4-22497
Syrius
2001-11-07 09:13
2002.01.08
Delphi 6 and Win32 API


1-22195
Lnix
2001-12-15 20:00
2002.01.08
string


6-22285
Vital
2001-10-09 12:34
2002.01.08
The problem of choice


4-22473
amamed_3071
2001-11-02 13:46
2002.01.08
Epson Printer commands


1-22003
Virtualik
2001-12-17 16:09
2002.01.08
TListItems





afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic indonesian Irish italian Japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Spanish swahili Swedish thai turkish Ukrainian urdu vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada Khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish