android-canvas

Android : Draw Circle With Text Inside

拜拜、爱过 提交于 2019-11-27 08:35:25
I need to draw three circles in my fragment ,the circles differ in size, I refer this link The result i obtained is this This is my XML Code : UPDATED <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" > <TextView android:id="@+id/large_volume" android:layout_width="185dp" android:layout_height="185dp" android:background="@drawable/circle" android:gravity="center" android:text="My name is NON" android:textColor="#FFFFFF" android

Android View.onDraw() always has a clean Canvas

假如想象 提交于 2019-11-27 07:28:40
I am trying to draw an animation. To do so I have extended View and overridden the onDraw() method. What I would expect is that each time onDraw() is called the canvas would be in the state that I left it in and I could choose to clear it or just draw over parts of it (This is how it worked when I used a SurfaceView) but each time the canvas comes back already cleared. Is there a way that I can not have it cleared? Or maybe save the previous state into a Bitmap so I can just draw that Bitmap and then draw over top of it? I'm not sure if there is a way or not. But for my custom views I either

Bezier curve and canvas

↘锁芯ラ 提交于 2019-11-27 07:27:46
How I can draw bezier curve in canvas. I have only start point and end point. I want to draw line from start point to end point. How I can do this? Renard You can use Path.quadTo() or Path.cubicTo() for that. Examples can be found in the SDK Examples (FingerPaint). In your case you would simply need to calculate the middle point and pass then your three points to quadTo() .. Some code for you: (x1,y1) and (x3,y3) are your starting and ending points respectively. create the paint object only once (e.g. in your constructor) Paint paint = new Paint() { { setStyle(Paint.Style.STROKE); setStrokeCap

Crop square image to circle - Programmatically

前提是你 提交于 2019-11-27 06:45:56
i was searching for past one day and i was not successful . i get the image from API , and i download it to a bitmap file using the following code . private Bitmap DownloadImage(String URL) { Bitmap bitmap = null; InputStream in = null; try { in = OpenHttpConnection(URL); bitmap = BitmapFactory.decodeStream(in); in.close(); } catch (IOException e1) { e1.printStackTrace(); } return bitmap; } private InputStream OpenHttpConnection(String urlString) throws IOException { InputStream in = null; int response = -1; URL url = new URL(urlString); URLConnection conn = url.openConnection(); if (!(conn

How to draw path with variable width in canvas

烂漫一生 提交于 2019-11-27 06:31:00
问题 I am using the following line of code to draw path on a Canvas, So far everything works fine and i can easily draw path using this code. But now our requirement is to draw path with variable width, means the path user draw is based on the pressure applied by the user, I mean to say if the user applied light pressure the path will be thin and if the user applied high pressure the path will be thick and so on. So far i succeeded in drawing path with variable width also, but the line drawn are

How to outline a TextView?

泪湿孤枕 提交于 2019-11-27 06:18:16
问题 What I want to do? (blue will be changed as white) What I did? I have found a class which extends TextView that able to outline textview very close to what I want. The problem is that I could not change stroke color to any color, it draws always as black. How to set border color as white? What is my output: Where are my codes? public class TypeFaceTextView extends TextView { private static Paint getWhiteBorderPaint(){ Paint p = new Paint(Color.WHITE); return p; } private static final Paint

Saving canvas to bitmap on Android

夙愿已清 提交于 2019-11-27 06:16:11
问题 I'm having some difficulty with regards to placing the contents of a Canvas into a Bitmap. When I attempt to do this, the file gets written with a file size of around 5.80KB but it appears to be completely empty (every pixel is '#000'). The canvas draws a series of interconnected lines that are formed by handwriting. Below is my onDraw for the View. (I'm aware that it's blocking the UI thread / bad practices/ etc.., however I just need to get it working) Thank you. @Override protected void

How to draw large sized text on a canvas?

独自空忆成欢 提交于 2019-11-27 06:15:40
问题 I want to draw on canvas month's text vertical along screen height. Paint init: this.paint = new Paint(); this.paint.setAntiAlias(true); this.paint.setDither(true); this.paint.setSubpixelText(true); this.paint.setColor(color_text_dark); this.paint.setTextAlign(Align.RIGHT); Drawing: // Set the scale to the widest month float scale = getHeight() / this.max_month_width; String month_string = FULL_MONTH_NAME_FORMATTER. format(active_month_calendar.getTime()); canvas.save(); canvas.translate

Android Center text on canvas

偶尔善良 提交于 2019-11-27 05:49:27
I'm trying to display a text using the code below. The problem is that the text is not centered horizontally. When I set the coordinates for drawText , it sets the bottom of the text at this position. I would like the text to be drawn so that the text is centered also horizontally. This is a picture to display my problem further: @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); //canvas.drawRGB(2, 2, 200); Paint textPaint = new Paint(); textPaint.setARGB(200, 254, 0, 0); textPaint.setTextAlign(Align.CENTER); textPaint.setTypeface(font);

Getting the pixel color value of a point on an Android View that includes a Bitmap-backed Canvas

只愿长相守 提交于 2019-11-27 04:50:13
I'm trying to figure out the best way to get the pixel color value at a given point on a View . There are three ways that I write to the View: I set a background image with View.setBackgroundDrawable(...) . I write text, draw lines, etc., with Canvas.drawText(...) , Canvas.drawLine(...) , etc., to a Bitmap-backed Canvas . I draw child objects (sprites) by having them write to the Canvas passed to the View's onDraw(Canvas canvas) method. Here is the onDraw() method from my class that extends View: @Override public void onDraw(Canvas canvas) { // 1. Redraw the background image. super.onDraw