Tag Archives: canvas

How to make canvas with Swing?

Questions: I’m trying to make a paint editor with Java in which I have a toolbar with the objects that I would like to paste in the canvas. I’m using Swing components to make the GUI, but when I looked for the way of making the canvas, I only found the class canvas from AWT.… Read More »

How to draw circle by canvas in Android?

Questions: I want to draw circle by canvas. Here is my code: [MyActivity.java]: public class MyActivity extends Activity { public void onCreate(Bundle savedInstanceState) { … setContentView(new View(this,w,h)); } } [View.java]: public class View extends SurfaceView { public View(Context context, int w, int h) { super(context); Canvas grid = new Canvas(Bitmap.createBitmap(h,w, Bitmap.Config.ARGB_8888)); grid. drawColor(Color.WHITE); Paint paint… Read More »

How to draw a filled triangle in android canvas?

Questions: So I’m drawing this triangle in android maps using the code below in my draw method: paint.setARGB(255, 153, 29, 29); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); Path path = new Path(); path.moveTo(point1_returned.x, point1_returned.y); path.lineTo(point2_returned.x, point2_returned.y); path.moveTo(point2_returned.x, point2_returned.y); path.lineTo(point3_returned.x, point3_returned.y); path.moveTo(point3_returned.x, point3_returned.y); path.lineTo(point1_returned.x, point1_returned.y); path.close(); canvas.drawPath(path, paint); The pointX_returned are the coordinates which I’m getting from the fields. They… Read More »

Automatically resize Canvas to fill the enclosing Parent

Questions: I recently wanted to create an animated background in JavaFX, similar to the Swing example seen here. I used a Canvas on which to draw, as shown in Working with the Canvas API, and an AnimationTimer for the drawing loop, as shown in Animation Basics. Unfortunately, I’m not sure how to resize the Canvas… Read More »

Saving Div Contents or Canvas as Image

Questions: I have read a few similar questions and answers, but none completely address my issue. Here is My Scenario: I have what is similar to a tinyMCE (a home-brew version though) kind of editor. It lets users enter some text, and an image or two, etc. I have code that takes the items in… Read More »

Canvas arc clearing

Questions: How do I overwrite an HTML5 canvas arc? I presumed this code would work but it leaves a border around it despite the fact that its exactly the same values and just a different colour.. Is there a border property I’m missing?? <!DOCTYPE html> <html> <head> <title>Test</title> </head> <body> <canvas id=”surface” width=”300″ height=”300″></canvas> <script… Read More »

What is the default quality for HTML5 Canvas.toDataURL?

Questions: According to mozilla, the second parameter for canvas.toDataURL(1,2) is: If the requested type is image/jpeg or image/webp, then the second argument, if it is between 0.0 and 1.0, is treated as indicating image quality; if the second argument is anything else, the default value for image quality is used. Other arguments are ignored. But… Read More »

PhoneGap games, canvas and slow javascript

Questions: So I built what I hoped would become a simple android game. I first built a web version to getting it working (http://scolvin.com/ballgame) then moved it to PhoneGap and used accelerometers to control the game. The only problem (and it’s a show stopping problem) is that the result is horrifically slow (updates i guess… Read More »