Page 1 of 1

How to paint directly on canvas?

Posted: Wed Feb 22, 2012 4:39 pm
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.

Posted: Wed Feb 22, 2012 6:35 pm
by Sergey Tkachenko
See Demos\*\Assorted\Custom Draw\CustomDraw\

Posted: Thu Feb 23, 2012 5:36 pm
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;

Posted: Fri Feb 24, 2012 3:55 pm
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.

Posted: Tue Feb 28, 2012 7:05 am
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

Posted: Tue Feb 28, 2012 11:56 am
by Sergey Tkachenko
Use TSRVPaintBox from SRVControls.

Posted: Tue Feb 28, 2012 1:46 pm
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.

Posted: Tue Feb 28, 2012 1:55 pm
by danten
I would be grateful if you sent me a small demo in writing to the SRV, while drawing the line width option.

Posted: Tue Feb 28, 2012 2:17 pm
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.

Posted: Tue Feb 28, 2012 4:52 pm
by danten
Thank definitely wait for the show and give your advice and how to draw the fastest procedure.

Thank you again.

Posted: Thu Mar 01, 2012 3:15 pm
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

Posted: Thu Mar 01, 2012 5:34 pm
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).

Posted: Fri Mar 02, 2012 9:52 am
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.

Posted: Sat Mar 03, 2012 9:10 am
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

Posted: Sat Mar 17, 2012 7:18 am
by danten
Sergey Tkachenko wrote:
Hello
and after thorough testing demo already understand.

Thank you very much.