Getting a DrawingContext for a wpf WriteableBitmap

I found sixlettervariables’ solution the most workable one. However, there’s a “drawingContext.Close()” missing. According to MSDN, “A DrawingContext must be closed before its content can be rendered”. The result is the following utility function: public static BitmapSource CreateBitmap( int width, int height, double dpi, Action<DrawingContext> render) { DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext drawingContext … Read more

How to draw a rounded rectangle in c#

public static GraphicsPath RoundedRect(Rectangle bounds, int radius) { int diameter = radius * 2; Size size = new Size(diameter, diameter); Rectangle arc = new Rectangle(bounds.Location, size); GraphicsPath path = new GraphicsPath(); if (radius == 0) { path.AddRectangle(bounds); return path; } // top left arc path.AddArc(arc, 180, 90); // top right arc arc.X = bounds.Right – … Read more

How to draw an updating line

You need to have two drawing calls: One for the non-persistent line that follows the cursor in the MouseMove using someControls.CreateGraphics the other for the persisting line, triggered in the MouseUp, where you store the coordinates and call Invalidate on your canvas control and draw in the Paint event of your canvas using its e.Graphics … Read more

Creating an empty bitmap and drawing though canvas in Android

This is probably simpler than you’re thinking: int w = WIDTH_PX, h = HEIGHT_PX; Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap Canvas canvas = new Canvas(bmp); // ready to draw on that bitmap through that canvas Here’s the official documentation on … Read more

How to place multiple evenly-spaced arrowheads along an SVG line?

Based on a clarification of the question, here’s an implementation of creating intermediary points along a <polyline> element such that the marker-mid=”url(#arrowhead)” attribute will work. See below that for an introduction to markers and arrowheads. Demo: http://jsfiddle.net/Zv57N/ midMarkers(document.querySelector(‘polyline’),6); // Given a polygon/polyline, create intermediary points along the // “straightaways” spaced no closer than `spacing` distance … Read more

Draw on the screen without a form

Method 1: Call the Windows API You need System.Drawing and System.Runtime.InteropServices. You may need to add project references to them. using System.Runtime.InteropServices; using System.Drawing; Add the methods to your class with P/Invoke [DllImport(“User32.dll”)] public static extern IntPtr GetDC(IntPtr hwnd); [DllImport(“User32.dll”)] public static extern void ReleaseDC(IntPtr hwnd, IntPtr dc); Get a Graphics object for the entire … Read more

How to draw a line between draggable and droppable?

updated (08.Jul.2013) Updated with latest versions of libraries; html refactored using JsRender; updated (29.Sep.2011) Added GIT Repo; cleaned the code; update to latest framework versions; updated (03.Mar.2013) Fixed links with working example; Current example uses: HTML 5 doctype jQuery v.1.10.2 jQuery UI v.1.10.3 Raphael v.2.0.1 JsRender v.1pre35 (optional, used for HTML simplification) Source Source code … Read more

Java – opaque color

The result depends on which compositing rule is specified in the graphics context using setComposite(). This utility may be useful in understanding the various modes. It may also help you in preparing an sscce that exhibits the problem you describe. Addendum: Here’s an example that shows how one might use AlphaComposite.Src mode for this. import … Read more