Questions tagged [android-canvas]

The Android Java Canvas (android.graphics.Canvas)

This is the tag for the Android Java Canvas, android.graphics.Canvas (official documentation).

If your question is about HTML5 (JavaScript) Canvas on Android devices please tag it and .

3799 questions
75
votes
7 answers

How to draw circle by canvas in Android?

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)); } …
pvl
  • 958
  • 1
  • 6
  • 12
70
votes
1 answer

Looking for an explanation of post/pre/set Translate (in Matrix object) and how to use them

The documentation is pretty vague as to what is actually happening when these methods are used. Can someone explain how Matrix actually affects the Bitmap that it's being set to? They use the term concatenate in there, but I'm unclear on how that…
Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
70
votes
14 answers

Android: How to detect when a scroll has ended

I am using the onScroll method of GestureDetector.SimpleOnGestureListener to scroll a large bitmap on a canvas. When the scroll has ended I want to redraw the bitmap in case the user wants to scroll further ... off the edge of the bitmap, but I…
prepbgg
  • 3,564
  • 10
  • 39
  • 51
65
votes
3 answers

How do the pieces of Android's (2D) Canvas drawing pipeline fit together?

I would like to have a better understanding of how the components of Android's (2D) Canvas drawing pipeline fit together. For example, how do XferMode, Shader, MaskFilter and ColorFilter interact? The reference docs for these classes are pretty…
Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
64
votes
11 answers

Android canvas: draw transparent circle on image

I am creating a pixel-hunting game. So my activity shows an ImageView. And I want to create a hint "show me where is the object". For this I need to blur whole image except a circle around a point where the object is located. Instead of blur I can…
Robert
  • 3,471
  • 3
  • 21
  • 24
64
votes
3 answers

android canvas drawText set font size from width?

I want to draw text on canvas of certain width using .drawtext For example, the width of the text should always be 400px no matter what the input text is. If input text is longer it will decrease the font size, if input text is shorter it will…
Badal
  • 3,738
  • 4
  • 33
  • 60
62
votes
3 answers

Drawing a filled rectangle with a border in android

Is there any way in Android to draw a filled rectangle with say a black border. My problem is that the canvas.draw() takes one paint object, and to my knowledge the paint object can't have a different color for the fill and the stroke. Is there a…
Uwais Iqbal
  • 910
  • 1
  • 8
  • 14
61
votes
2 answers

How to set gradient style to paint object?

The code for drawing an arrow with Style: Fill is given below: paint.setColor(Color.parseColor("#bdc0dc")); paint.setStyle(Style.FILL); canvas.drawPath(arrowPath,…
Rohan K
  • 1,608
  • 4
  • 21
  • 32
61
votes
3 answers

What does top, left, right and bottom mean in Android Rect object

I have an Android project where I should make Apples fall. The apples are painted in a Rect. So I created a function that change the Rect position and repaint. Here's my function : private void updateApplesPosition() { for(Rect…
Hunsu
  • 3,281
  • 7
  • 29
  • 64
58
votes
4 answers

What does canvas.translate do?

An example can be found here compass.java. Api here
Vincent
  • 6,058
  • 15
  • 52
  • 94
58
votes
3 answers

Can I draw with antialiasing on canvas?

Can I draw with anti-aliasing on canvas? I need my circles and line have smooth edges.
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
57
votes
2 answers

Rect and RectF in Android SDK

What is the difference between Rect and RectF in the Android SDK?
Iulius Curt
  • 4,984
  • 4
  • 31
  • 55
56
votes
5 answers

Save canvas then restore, why is that?

I often see the following code canvas.save(). canvas translate or rotate some drawing canvas.restore I don't understand why we save and then restore. What's the point of undoing what we just did! I am sure I am missing something here Thanks
Snake
  • 14,228
  • 27
  • 117
  • 250
53
votes
4 answers

converting a canvas into bitmap image in android

I am trying to develop an app on canvas,I am drawing a bitmap on the canvas. After drawing, I am trying to convert into bitmap image. Can anyone give me a suggestion?
satyam
  • 535
  • 1
  • 5
  • 8
51
votes
7 answers

How to draw Arc between two points on the Canvas?

I have two points in the canvas, now I'm able to draw a line between those points like this below image by using This code canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint); I want to draw the arc between two points like below image. How can I draw…
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166