InkCanvas (ink panel) usage in WPF

Source: Internet
Author: User
InkCanvas (ink panel) usage in WPF
Zhou yinhui

ThanksWhen a BarberThis Cool Demo is provided for us.
You can download to it http://files.cnblogs.com/zhouyinhui/InkCanvas.rar here

The following are common usage of InkCanvas (assume that our InkCanvas object is inkCanv ):

Save

You can choose to save ink as an ink file or as an image

Save as an ink file (*. isf): this. inkCanv. Strokes. Save (file );

Where file is the file stream to be saved (FileStream)

Save as image:
We can first draw ink on the image and then save the image. To draw the Visual object to the image, we can use the RenderTargetBitmap class and use its Render () method. to Save an image, you can use the BitmapEncoder class and call its Save () method. renderTargetBitmap rtb = new RenderTargetBitmap (width, height, 0, 0, PixelFormats. default );
Rtb. Render (this. inkCanv );
BMP bitmapencoder encoder = new BMP bitmapencoder ();
Encoder. Frames. Add (BitmapFrame. Create (rtb ));
Encoder. Save (file );

Open

To open a saved ink file (*. isf), use the following method: this. inkCanv. Strokes = new StrokeCollection (file );

Selected

Like a canvas, you can select certain elements to be drawn. You can select the elements by using the mouse or by using the code.

Select with the mouse
You only need to switch the editing mode of InkCanvas. The EditingMode attribute of InkCanvas is of the InkCanvasEditingMode Enumeration type. You can switch the value to InkCanvasEditingMode. Select to enter the selected mode.

Select using code
You can call the Select () method of InkCanvas.

Copy, cut, paste, or delete a selected object

These operations are relatively simple. InkCanvas has corresponding methods: CopySelection (), CutSelection (), Past (), and Remove ().

Eraser

To use an eraser, The EditingMode attribute of InkCanvas is also switched. There are two erasure modes: InkCanvasEditingMode. eraseByPoint (point-by-point erasure) and InkCanvasEditingMode. eraseByStroke (erased by ink strokes, one uninterrupted stroke ).

Handwriting color, thickness...

To change the handwriting attributes, you can set the DefaultDrawingAttributes attribute of InkCanvas, for example, DrawingAttributes inkd = new DrawingAttributes ();
Inkd. Width = 5;
Inkd. Height = 5;
Inkd. Color = Color. FormArgb (255,255,255,255 );
This. inkCanv. DefaultDrawingAttributes = inkd;

InkCanvas also has many interesting functions. You can refer to the InkCanvas class in the SDK for more information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.