How to paint directly on canvas?

General TRichView support forum. Please post your questions here
Post Reply
danten
Posts: 9
Joined: Wed Feb 22, 2012 4:33 pm

How to paint directly on canvas?

Post by danten »

How to paint directly on canvas?
If I use the classic painting, so I always line snaps to the cursor.

Currently I use a procedure to insert the RVE TImage and then paint it.
This is not the optimal solution and do not know how to calculate the size of the embedded TImage from the cursor position to the right and bottom of the page.
Can you give me a link to the demo, which is solved RVE painting on canvas?
Thank you very much.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

See Demos\*\Assorted\Custom Draw\CustomDraw\
danten
Posts: 9
Joined: Wed Feb 22, 2012 4:33 pm

Post by danten »

Sergey Tkachenko wrote:See Demos\*\Assorted\Custom Draw\CustomDraw\
Thank you, but this does not solve my problem.
I need to manually draw Canvas RVE.
The solution with TImage I took only an option if you will not draw directly on Cnavas RVE.
I do not know how to incorporate position location.

I used method:

Code: Select all

var
  Draw: boolean;
begin
Image1.Parent: = RVE;


and until then I just cut a section drawn in image2:

Code: Select all

procedure TEditor.ScanImage;
var
   XIndex, YIndex, xmin, xmax, ymin, ymax: integer;
   DstRect, SrcRect: TRect;
   bmp: TBitmap;
begin
   Xmin: = image1.ClientWidth;
   Ymin: = image1.ClientHeight;
   Xmax: = 0;
   Ymax: = 0;
   YIndex for: = 0 to image1.ClientHeight - 1 to
     XIndex for: = 0 to image1.ClientWidth - 1 to
       if image1.Canvas.Pixels [XIndex, YIndex] <>
         image1.Canvas.Brush.Color then
         begin
           if XIndex <xmin then
             Xmin: = XIndex;
           if YIndex <ymin then
             Ymin: = YIndex;
           if XIndex> xMax then
             Xmax: = XIndex;
           if YIndex> ymax then
             Ymax: = YIndex;
         end;

   bmp: = TBitmap.Create;
   try
     Bmp.PixelFormat: = pf32bit;
     Bmp.Width: = (Xmax-Xmin) +2;
     Bmp.Height: = (ymax-ymin) +2;
     BMP.Transparent: = True;
     bmp.TransparentColor: = image1.Canvas.Brush.Color;
     bmp.TransparentMode: = tmAuto;
     bmp.Canvas.CopyMode: = cmSrcCopy;
     DstRect: = Rect (0, 0, bmp.Width, bmp.height);
     SrcRect: = Rect (xmin -1, ymin -1, +2 Xmax, ymax +2);
     bmp.Canvas.CopyRect (DstRect, image1.Canvas, SrcRect);
     Image2.Picture.Bitmap.Assign (bmp);
     bmp.SaveToFile ('C:\\test.bmp');
??? RVE add Image BMP ???
   finally
     Bmp.Free;
   end;
end;

procedure TEditor.RVEMouseMove (Sender: TObject;
   Shift: TShiftState, X, Y: Integer);
begin
    if draw = True then image1.canvas.lineto (x, y);
end;

procedure TEditor.RVEMouseUp (Sender: TObject;
   Button: TMouseButton; Shift: TShiftState, X, Y: Integer);
begin
   draw: = false;
   ScanImage;
end;
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, I do not understand where do you want to draw.
If you want to draw on TRichViewEdit canvas, you can use OnPaint event.

If you want to implement a custom drawn item, probably drawing on a bitmap/metafile and inserting it in TRichViewEdit is the best solution. Or you can insert TPaintBox component.
danten
Posts: 9
Joined: Wed Feb 22, 2012 4:33 pm

Post by danten »

Hello
I'm sorry but just because I do not know how to draw on the canvas SRichViewEdit so I wanted to resolve the insertion of TImage.

If there is the possibility to insert TPaintBox then how do I draw the image into ScaleRichView.

Please demo if possible.
If possible, the fastest alternative.

thank you very much
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use TSRVPaintBox from SRVControls.
danten
Posts: 9
Joined: Wed Feb 22, 2012 4:33 pm

Post by danten »

Sergey Tkachenko wrote:Use TSRVPaintBox from SRVControls.
Thank you for your patience, but I fear that without the code samples can not make it.
I am not a professional programmer, but self-taught.
This what I write here is for me to reverse engineering.
danten
Posts: 9
Joined: Wed Feb 22, 2012 4:33 pm

Post by danten »

I would be grateful if you sent me a small demo in writing to the SRV, while drawing the line width option.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I'll try to make the example tomorrow.
However, working with Bitmap.Pixels is very slow, so may be drawing into a bitmap and inserting this bitmap would be a better solution.
danten
Posts: 9
Joined: Wed Feb 22, 2012 4:33 pm

Post by danten »

Thank definitely wait for the show and give your advice and how to draw the fastest procedure.

Thank you again.
danten
Posts: 9
Joined: Wed Feb 22, 2012 4:33 pm

Post by danten »

danten wrote:Thank definitely wait for the show and give your advice and how to draw the fastest procedure.

Thank you again.
Hello
I continue to ask how the demo example.

thank you
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

After studying your code, I am not sure that I understand what you want to draw.
1) Why all this complication in ScanImage? Why don't you just insert an image from Image1 in SRichViewEdit?
2) To make sure, do you want to work with TSRichViewEdit (i.e. ScaleRichView) or TRichViewEdit?
3) As I understand, you want to draw a line to the mouse pointer then a mouse button is pressed. Ok, the line end at the mouse pointer, but where does it start?
4) What if you inserted several such images?

PS: unfortunately, TSRichViewEdit does not support transparency in images (unlike TRichViewEdit).
danten
Posts: 9
Joined: Wed Feb 22, 2012 4:33 pm

Post by danten »

Hello
I'd like to create a text editor with drawing something like MS Word.
In MS Word, write, and then click on the "Insert" -> "Shapes" and drawing on canvas.

Scanline I wanted to use if I had inserted as a Parent SRichView ana TImage it drew.
This solution was only a test.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

There is a difference if you want to draw inside the item rectangle or in arbitrary place of the editor canvas. The former is easier: you can use pictures or paint-boxes.

I created a simple demo for inserting figures in TSRichViewEdit:
http://www.trichview.com/support/files/srvfigures.zip
This demo requires installed SRVControls.

It shows 3 ways of adding shapes in the editor:
1) paint-boxes (TSRVPaintBox)
2) images - bitmaps
3) images - metafiles
danten
Posts: 9
Joined: Wed Feb 22, 2012 4:33 pm

Post by danten »

Sergey Tkachenko wrote:
Hello
and after thorough testing demo already understand.

Thank you very much.
Post Reply