Draw arrow on canvas tag

As simple as I can get it. You’ll have to prepend context.beginPath() and append context.stroke() yourself: ctx = document.getElementById(“c”).getContext(“2d”); ctx.beginPath(); canvas_arrow(ctx, 10, 30, 200, 150); canvas_arrow(ctx, 100, 200, 400, 50); canvas_arrow(ctx, 200, 30, 10, 150); canvas_arrow(ctx, 400, 200, 100, 50); ctx.stroke(); function canvas_arrow(context, fromx, fromy, tox, toy) { var headlen = 10; // length of … Read more

Drawing class drawing straight lines instead of curved lines

There are a few issues: You are using control points that are midpoints between the two points, resulting in line segments. You probably want to choose control points that smooth the curve. See http://spin.atomicobject.com/2014/05/28/ios-interpolating-points/. Here is a Swift 3 implementation of a simple smoothing algorithm, as well as Swift renditions of the above Hermite and … Read more

how to stop flickering C# winforms

For a “cleaner solution” and in order to keep using the base Panel, you could simply use Reflection to implement the double buffering, by adding this code to the form that holds the panels in which you want to draw in typeof(Panel).InvokeMember(“DoubleBuffered”, BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, DrawingPanel, new object[] { true }); Where … Read more

Convert bitmaps to one multipage TIFF image in .NET 2.0

Start with the first bitmap by putting it into an Image object Bitmap bitmap = (Bitmap)Image.FromFile(file); Save the bitmap to memory as tiff MemoryStream byteStream = new MemoryStream(); bitmap.Save(byteStream, ImageFormat.Tiff); Put Tiff into another Image object Image tiff = Image.FromStream(byteStream) Prepare encoders: var encoderInfo = ImageCodecInfo.GetImageEncoders().First(i => i.MimeType == “image/tiff”); EncoderParameters encoderParams = new EncoderParameters(2); … Read more

How to render pdfs using C#

Google has open sourced its excellent PDF rendering engine – PDFium – that it wrote with Foxit Software. There is a C# nuget package called PdfiumViewer which gives a C# wrapper around PDFium and allows PDFs to be displayed and printed. I have used it and was very impressed with the quality of the rendering. … Read more

How to drag and move shapes in C#

To hit test shapes you don’t need linear algebra. You can create GraphicsPath for your shapes and then using GraphicsPath.IsVisible method or GraphicsPath.IsOutlineVisible method perform hit-testing. To check if a point is in the area of your path, for example a filled shape, use IsVisible. To hit-test for lines or curves or empty shapes, you … Read more