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]

Никак не получается распечать Image с точными размерами. Он все равно распечатывается неправильно.
Делаю я так. Нахожу размеры Bitmapa в inch:

sx,sy:real;
ABitmap:=Image1.Picture.Bitmap;
sx:=ABitmap.Width/GetDeviceCaps(image1.canvas.handle,LOGPIXELSX);
sy:=ABitmap.Height/GetDeviceCaps(image1.canvas.handle,LOGPIXELSY);


Теперь нахожу размеры в пикселах на принтере для распечатки:

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, SRCCOPY);
finally
FreeMem(Header, HeaderSize);
FreeMem(Bits, BitsSize);
end;
end;


Все это печатает с неверными размерами. Где же ошибка?

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.82 MB
Time: 0.031 c
6-22285
Vital
2001-10-09 12:34
2002.01.08
The problem of choice


3-21968
olban
2001-12-05 11:20
2002.01.08
QuantumGrid


1-22147
vinni2000
2001-12-20 12:59
2002.01.08
Need advice on RichEdit !!!!!!!!


1-22180
Nathan
2001-12-21 11:07
2002.01.08
Problem!


14-22390
Hedgehog
2001-11-08 12:54
2002.01.08
Listen Merlin, do you ever sleep? In a sense, relaxing?





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 Español 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