Draw a rectangle in Golang?

The standard Go library does not provide primitive drawing or painting capabilities. What it provides is models for colors (image/color package) and an Image interface with several implementations (image package). The blog post The Go Image package is a good introduction to this. It also provides a capability to combine images (e.g. draw them on … Read more

Android: looking for a drawArc() method with inner & outer radius

You can do this: Paint paint = new Paint(); final RectF rect = new RectF(); //Example values rect.set(mWidth/2- mRadius, mHeight/2 – mRadius, mWidth/2 + mRadius, mHeight/2 + mRadius); paint.setColor(Color.GREEN); paint.setStrokeWidth(20); paint.setAntiAlias(true); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStyle(Paint.Style.STROKE); canvas.drawArc(rect, -90, 360, false, paint); The key is in paint.setStyle(Paint.Style.STROKE);, it crops the arc’s center with the stroke that you define in … Read more

Write text on an image in C#

To draw multiple strings, call graphics.DrawString multiple times. You can specify the location of the drawn string. This example we will draw two strings “Hello”, “Word” (“Hello” in blue color upfront “Word” in red color): string firstText = “Hello”; string secondText = “World”; PointF firstLocation = new PointF(10f, 10f); PointF secondLocation = new PointF(10f, 50f); … Read more

How to draw in JPanel? (Swing/graphics Java)

Note the extra comments. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; class JavaPaintUI extends JFrame { private int tool = 1; int currentX, currentY, oldX, oldY; public JavaPaintUI() { initComponents(); } private void initComponents() { // we want a custom Panel2, not a generic JPanel! jPanel2 = new Panel2(); jPanel2.setBackground(new java.awt.Color(255, 255, 255)); jPanel2.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); … Read more

clearRect function doesn’t clear the canvas

You should use “beginPath()“. That is it. function lineDraw() { var canvas=document.getElementById(“myCanvas”); var context=canvas.getContext(“2d”); context.clearRect(0, 0, context.width,context.height); context.beginPath();//ADD THIS LINE!<<<<<<<<<<<<< context.moveTo(0,0); context.lineTo(event.clientX,event.clientY); context.stroke(); }