android-canvas

How to use android canvas to draw a Rectangle with only topleft and topright corners round?

ⅰ亾dé卋堺 提交于 2019-11-26 10:32:38
问题 I found a function for rectangles with all 4 corners being round, but I want to have just the top 2 corners round. What can I do? canvas.drawRoundRect(new RectF(0, 100, 100, 300), 6, 6, paint); 回答1: You can draw that piece by piece using drawLine() and drawArc() functions from the Canvas . 回答2: Use a path. It has the advantage of working for APIs less than 21 (Arc is also limited thusly, which is why I quad). Which is a problem because not everybody has Lollipop yet. You can however specify a

Android Canvas.drawText

£可爱£侵袭症+ 提交于 2019-11-26 10:29:55
问题 I have a view, I\'m drawing with the Canvas object in the onDraw(Canvas canvas) method. My code is: Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setStyle(Style.FILL); canvas.drawPaint(paint); paint.setColor(android.R.color.black); paint.setTextSize(20); canvas.drawText(\"Some Text\", 10, 25, paint); The problem is the text doesn\'t show through the background, what am I doing wrong? If I remove the canvas.drawPaint(paint) and paint.setColor(android.R.color.black) you can see

How to blur some portion of Image in Android?

孤街浪徒 提交于 2019-11-26 09:52:41
问题 I am working in a project where I have to show some portion of the image clear and make rest part of the image blur. The blur should be managed by slider. Means it can be increase or decrease. The final result image should look alike below. During my research for this I found below links useful http://blog.neteril.org/blog/2013/08/12/blurring-images-on-android/ https://github.com/kikoso/android-stackblur http://blog.neteril.org/blog/2013/08/12/blurring-images-on-android/ But the issue in

Creating an empty bitmap and drawing though canvas in Android

倖福魔咒の 提交于 2019-11-26 09:19:59
问题 I\'d like to create an empty bitmap and set a canvas to that bitmap and then draw any shape on the bitmap. 回答1: This is probably simpler than you're thinking: int w = WIDTH_PX, h = HEIGHT_PX; Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap Canvas canvas = new Canvas(bmp); // ready to draw on that bitmap through that canvas Here's a series of tutorials I've found on the topic: Drawing with

SurfaceView flashes black on load

陌路散爱 提交于 2019-11-26 09:17:09
问题 I have a drawing app that takes about 2-5 seconds to load the drawing for complicated drawings (done via an AsyncTask ). For a better user experience, during this time I flash the stored PNG version of the drawing I have from the app directory as an ImageView , and show a loading ProgressBar calling setContentView() in the Activity constructor: <?xml version=\"1.0\" encoding=\"utf-8\"?> <FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" android:layout_width=\"match

How to draw circle by canvas in Android?

为君一笑 提交于 2019-11-26 08:56:12
问题 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 = new Paint(); paint.setStyle(Paint.Style.FILL); grid

Draw in Canvas by finger, Android

大兔子大兔子 提交于 2019-11-26 08:50:53
问题 I need to build a project for drawing on canvas by fingers, to get the touch event and motion event of my finger, and thence draw. Any one can advice me how to get start in project, and what is best component to do thing like this? 回答1: Start By going through the Fingerpaint demo in the sdk sample. Another Sample: public class MainActivity extends Activity { DrawingView dv ; private Paint mPaint; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState)

converting a canvas into bitmap image in android

本秂侑毒 提交于 2019-11-26 08:11:54
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. thank you in advance. Advice depends upon what you are trying to do. If you are concerned that your controls take a long time to draw, and you want to draw to a bitmap so you can blit the bitmap rather than re-drawing via a canvas, then you don't want to be double-guessing the platform - controls automatically cache their drawing to temporary bitmaps, and these can even be fetched from the control using getDrawingCache() If you

How to draw Arc between two points on the Canvas?

帅比萌擦擦* 提交于 2019-11-26 08:03:35
问题 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 like this. 回答1: Finally I got the solution from this code: float radius = 20; final RectF oval = new RectF(); oval.set(point1.x - radius, point1.y - radius, point1.x + radius, point1.y+ radius); Path myPath = new Path(); myPath.arcTo(oval, startAngle

Android: How to detect when a scroll has ended

别来无恙 提交于 2019-11-26 07:57:33
问题 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 can\'t see how to detect when the scroll has ended (the user has lifted his finger from the screen). e2.getAction() always seems to return the value 2 so that is no help. e2.getPressure seems to return fairly constant values (around 0.25) until the