C
czx_china
Unregistered / Unconfirmed
GUEST, unregistred user!
我想把RichEdit的内容利用下面提供的程序打印到BMP上,但我怎么知道打印的内容是多宽多高?或者我设定BMP大小过,能知道已经打满,要求换页也好?
procedure TForm1.Button1Click(Sender: TObject);
var
Range : TFormatRange;
LastChar, MaxLen, LogX, LogY: Integer;
BMP:TBitmap;
begin
FillChar(Range, SizeOf(TFormatRange), 0);
BMP:=TBitmap.Create;
BMP.PixelFormat:=pf24bit;
BMP.Width:=200;
BMP.Height:=200;
with BMP.Canvas do
begin
Brush.Style:=bsSolid;
Brush.Color:=clBlack;
FillRect(ClipRect);
end;
with Range do
begin
LogX := GetDeviceCaps(BMP.Canvas.Handle, LOGPIXELSX);
LogY := GetDeviceCaps(BMP.Canvas.Handle, LOGPIXELSY);
hdc := BMP.Canvas.Handle;
hdcTarget := hdc;
rc.right := BMP.Width * 1440 div LogX;//Image1.ClientWidth * 1440 div LogX;
rc.bottom := BMP.Height * 1440 div LogY;//Image1.ClientHeight * 1440 div LogY;
rcPage := rc;
LastChar := 0;
MaxLen := Editor.GetTextLen;
chrg.cpMax := -1;
repeat
chrg.cpMin := LastChar;
LastChar := SendMessage(Editor.Handle, EM_FORMATRANGE, 1, Longint(@Range));
until (LastChar >= MaxLen) or (LastChar = -1);
end;
Image1.Picture.Assign(BMP);
BMP.free;
procedure TForm1.Button1Click(Sender: TObject);
var
Range : TFormatRange;
LastChar, MaxLen, LogX, LogY: Integer;
BMP:TBitmap;
begin
FillChar(Range, SizeOf(TFormatRange), 0);
BMP:=TBitmap.Create;
BMP.PixelFormat:=pf24bit;
BMP.Width:=200;
BMP.Height:=200;
with BMP.Canvas do
begin
Brush.Style:=bsSolid;
Brush.Color:=clBlack;
FillRect(ClipRect);
end;
with Range do
begin
LogX := GetDeviceCaps(BMP.Canvas.Handle, LOGPIXELSX);
LogY := GetDeviceCaps(BMP.Canvas.Handle, LOGPIXELSY);
hdc := BMP.Canvas.Handle;
hdcTarget := hdc;
rc.right := BMP.Width * 1440 div LogX;//Image1.ClientWidth * 1440 div LogX;
rc.bottom := BMP.Height * 1440 div LogY;//Image1.ClientHeight * 1440 div LogY;
rcPage := rc;
LastChar := 0;
MaxLen := Editor.GetTextLen;
chrg.cpMax := -1;
repeat
chrg.cpMin := LastChar;
LastChar := SendMessage(Editor.Handle, EM_FORMATRANGE, 1, Longint(@Range));
until (LastChar >= MaxLen) or (LastChar = -1);
end;
Image1.Picture.Assign(BMP);
BMP.free;