android-canvas

Draw a hollow circle on an Android Canvas

百般思念 提交于 2020-01-02 21:58:23
问题 I am working on creating a custom view where a user can select an angle. Below is an example of what the end result should look like: I am achieving this with the following code: mPaint.setColor(Color.BLACK); canvas.drawCircle((int) (mSize.right / 2), (int) (mSize.bottom / 2), mWidthOutside, mPaint); mPaint.setColor(Color.LTGRAY); canvas.drawCircle((int) (mSize.right / 2), (int) (mSize.bottom / 2), mWidthInside, mPaint); The problem with doing it this way, is the background is a static LTGRAY

Drawing two 3D strings on Canvas?

▼魔方 西西 提交于 2020-01-02 06:45:37
问题 I have to draw 2 Strings on canvas.Strings must be drawn with the same coordinates and second string must be result of rotating first string 45 degrees around axis Y.The result must looks like this: This is my code: Matrix matrix = new Matrix(); matrix = canvas.getMatrix(); mCamera = new Camera(); canvas.drawText("In the name of God", 30, 100, redPaint); mCamera.rotateY(45); mCamera.getMatrix(matrix); matrix.preTranslate(30, 100); // matrix.postTranslate(-30, -100); canvas.setMatrix(matrix);

How to draw several lines slowly in constant velocity on canvas by Android?

家住魔仙堡 提交于 2020-01-02 04:55:10
问题 I need capture the mark to draw a figure on canvas in Android, and the effect just like the follow gif: Well, as far, I can draw a side with constant velocity by ValueAnimator . However, I just only can draw one side at one time, because I can't save the last side when drawing the next side. So, is there a good way to solve the problem? Code for draw a line slowly by ValueAnimator: GraphicsView.java public class GraphicsView extends View { private int stepX, stepY = 0; private int startX,

PorterDuff masking leaves opaque black background

淺唱寂寞╮ 提交于 2020-01-01 19:20:55
问题 I'm trying to mask a FrameLayout with a mask defined as a nine patch. However, although it works fine on 5.0+ on older versions (such as 4.4.4), the patch leaves an opaque black background. Is there anything that can be done to avoid this other than drawing to an off screen bitmap before rendering to the screen or reverting to software layers? public class MaskedLayout extends FrameLayout { private final static PorterDuffXfermode DST_IN = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);

Android Canvas didn't draw Path when Path's point out of view

大兔子大兔子 提交于 2020-01-01 08:54:08
问题 I ran into some problem with Android Canvas when drawing path. My case is that i have a relative layout work like a map view ( not using google api or something like that ). I have to draw a path onto that view. canvas.drawPath(polyPath, borderPaint); I also have to draw other type like circle, polygon using canvas as well. Everytime we zoom in or zoom out, we re-calculate path point to match with zoom level. When using old api like android 2.3.3, there no problem at all. But for newer api

Draw a line with curved edges in Android

牧云@^-^@ 提交于 2020-01-01 08:43:58
问题 I am using canvas.drawLine to draw some line in android but the lines are too sharp but i need a curved edges Here the 1 is what i have and 2 is what i want to achieve, means a line with curved edges rather than straight edges How can I achieve that ?? EDIT 2: I am trying to use the Canvas object to to draw a line. but the lines have a sharp edge, I need a rounded off edge I am using the Paint object mPaint = new Paint(); mPaint.setColor(Color.BLACK) Any help is appreciated. Thank you 回答1:

How to use canvas of view extended class into activity class?

点点圈 提交于 2020-01-01 06:23:17
问题 I created one class: public class TestCanvas extends View { public TestCanvas(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setColor(Color.RED); canvas.drawText("kal", 0, 100, paint); canvas.save(); } } Now I call that class from activity: public class TestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R

How to drawing a path with a bitmap?

ぃ、小莉子 提交于 2020-01-01 05:02:30
问题 I have a little drawing app and want to use "complex" shapes as brushes, i.e. a star. Drawing with a simple brush already works with this code: remotePath.reset(); remotePath.moveTo(start_x, start_y); float dx = Math.abs(end_x - start_x); float dy = Math.abs(end_y - start_y); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { remotePath.quadTo(start_x, start_y, (end_x + start_x) / 2, (end_y + start_y) / 2); } remotePath.lineTo(end_x, end_y); // commit the path to our offscreen mCanvas

How to create a square bitmap from a rectangular bitmap in Android

南笙酒味 提交于 2020-01-01 03:27:08
问题 Basically, I have a rectangular bitmap and want to create a new Bitmap with squared dimensions which will contain the rectangular bitmap inside of it. So, for example, if the source bitmap has width:100 and height:400, I want a new bitmap with width:400 and height:400. Then, draw the source bitmap centered inside of this new bitmap (see attached image for a better understanding). My code below creates the square bitmap fine, but the source bitmap is not being drawn into it. As a result, I'm

creating a random circle that can be clicked on like a button

坚强是说给别人听的谎言 提交于 2019-12-31 06:42:05
问题 so here is my predicament i cannot seem to find this anywhere on the internet. My question is simple. I am creating a game app for android. The game will generate random circles on the screen that a user can click on then once the user does click on one of these random circles an action will occur. This is just like the function of the button, but different because the whole circle will be able to be clicked. i will post the random number generator that generates the circles this is not the