Z rich edita do bitmapy

0

Witam

Mam problem ze zczytaniem całego tekstu z richedita do bitmapy kod zczytuje tylko ten tekst który jest widoczny w oknie komponetu, natomiast pozostała zawartość nie jest zczytywana.

Dodaje obrazek żeby lepiej zrozumiec o co chodzi.

http://img716.imageshack.us/img716/8287/beztytuug.jpg

I kod:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, RichEdit;

type
  TForm1 = class(TForm)
    nico: TRichEdit;
    Button1: TButton;
    maluj: TImage;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
Function CreateEmptyBmp(myColor : TColor; Width,Height : Integer) : TBitmap;
Begin
  Result := TBitmap.Create;
  Result.Width := Width;
  Result.Height := Height;
  Result.Canvas.brush.Color := myColor;
  Result.Canvas.brush.Style := bsSolid;
  Result.Canvas.FillRect(Rect(0,0,Result.Width,Result.Height));
End;

function RTFtoBitmap(myRTF: TRichEdit; GiveSpaceForBorder: Integer): TBitmap;
var
  myRect: TRect;
  temp: TBitmap;
begin
  temp := TBitmap.Create;

  myRect := Rect(0,0,MyRTF.Width,MyRTF.Height);
  temp.Width  := myRect.Right;
  temp.Height := myRect.Bottom;
  with temp.Canvas do
  begin
    Lock;
    try
      myRTF.Perform(WM_PRINT, temp.Handle, PRF_NONCLIENT);
    finally
      Unlock
    end;
  end;
  Result := TBitmap.Create;
  Result := CreateEmptyBmp(clWhite,
    temp.Width + GiveSpaceForBorder * 2,
    temp.Height + GiveSpaceForBorder * 2);
  Result.Canvas.Lock;
  Result.Canvas.Draw(GiveSpaceForBorder, GiveSpaceForBorder, temp);
  Result.Canvas.Unlock;
  temp.Free;
end;



function PrintToCanvas(ACanvas : TCanvas; FromChar, ToChar : integer;
                      ARichEdit : TRichEdit; AWidth, AHeight : integer) : Longint;
var
  Range    : TFormatRange;
begin
    FillChar(Range, SizeOf(TFormatRange), 0);
    Range.hdc        := ACanvas.handle;
    Range.hdcTarget  := ACanvas.Handle;
    Range.rc.left    := 0;
    Range.rc.top     := 0;
    Range.rc.right   := AWidth * 1440 div Screen.PixelsPerInch;
    Range.rc.Bottom  := AHeight * 1440 div Screen.PixelsPerInch;
    Range.chrg.cpMax := ToChar;
    Range.chrg.cpMin := FromChar;
    Result := SendMessage(ARichedit.Handle, EM_FORMATRANGE, 1, Longint(@Range));
   SendMessage(ARichEdit.handle, EM_FORMATRANGE, 0,0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var bmp : TBitmap;
h,w: integer;
begin
  
  w :=nico.Width; //nico.CaretPos.x;//GetDeviceCaps(GetDC(nico.Handle),HorzSize);
  h :=nico.Height; //nico.PerForm(EM_GETFIRSTVISIBLELINE,15, 15);//BevelWidth//(GetDC(nico.Handle), PHYSICALOFFSETY);//GetDeviceCaps(GetDC(nico.Handle),VertSize);
  maluj.Picture.Bitmap:= TBitmap.Create;
  maluj.Picture.Bitmap.Height := h;
  maluj.Picture.Bitmap.Width := w;
  Button1.Caption:= inttostr(w)+':'+inttostr(h);
  PrintToCanvas(maluj.Picture.Bitmap.Canvas,3,nico.GetTextLen,nico,w,h);
    maluj.Refresh;


end;
</url>
0
maluj.Picture.Bitmap.Height := h;

Popracuj nad tą linijką, popatrz sobie we "własnym" kodzie jaką wartość przyjmuje h

1 użytkowników online, w tym zalogowanych: 0, gości: 1