android-canvas

Canvas.drawArc() artefacts

自古美人都是妖i 提交于 2019-12-20 10:44:59
问题 I draw an arc on canvas in a custom view as shown below. Paint and rectangle are defined outside of onDraw() and added in there for simplicity purpose. protected void onDraw(Canvas canvas) { super.onDraw(canvas); RectF rectangle = new RectF(60f, 60f, 480f, 480f); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(0x40000000); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(120); canvas.drawArc(rectangle, 225f, 315f, false, paint); } When I run this code on Galaxy

Save canvas then restore, why is that?

╄→尐↘猪︶ㄣ 提交于 2019-12-20 10:19:35
问题 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 回答1: I understand this question is a bit dated, but for anyone still looking for an answer I can ELI5; Imagine the canvas is a piece of paper, and you're tasked with drawing a picture of a robot right side up, at the bottom, and another robot upside down,

Draw bubble programmatically

喜夏-厌秋 提交于 2019-12-20 09:45:13
问题 I would like to have a bubble with a precentage value in my app, I can't use 9 patches as i want it to be customizable and its background color should be changeble. It should look something like this How can I do it? This bubble will have views inflated inside of it, like this percentage or some larger layouts. Also depending on the layout(phone or tablet) it might have one side larger than the other (arrow not at the center) so that's another reason i prefer doing it programmatically 回答1:

Canvas - zooming in, shifting, and scaling on Android

こ雲淡風輕ζ 提交于 2019-12-20 08:50:05
问题 I'm currently implementing a draw function on a webview image (the elephant below). I don't have a problem drawing on it but the zoom function does some funky stuff (2nd image below) on the drawing. When I zoom in, the drawing doesn't zoom but rather shifts over. Drawing at zoomed also doesn't work. My code is below: @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.save(); canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint); canvas.drawPath(drawPath, drawPaint);

android canvas drawText set font size from width?

余生长醉 提交于 2019-12-20 07:59:54
问题 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 increase the font size accordingly. 回答1: Here's a much more efficient method: /** * Sets the text size for a Paint object so a given string of text will be a * given width. * * @param paint * the Paint to set the text size for * @param desiredWidth *

Draw a circle within circle at a distance of 10

跟風遠走 提交于 2019-12-20 06:16:07
问题 I have recently started working with Android, And I need to draw a Circle within Circle just like below image at a distance of 10. If you see the below photo, I need to draw something like below circle with two diameters like that and I don't need any icons that are there currently on the photo. Just a Circle within Circle having two diameters. I want to draw only the circles and two diameter, not the icons on the circle. Any suggestions will be appreciated. Update:- I wrote the below code

android live wallpapers parallax-scrolling effect

大憨熊 提交于 2019-12-20 05:41:41
问题 when we scroll, the foreground of the home screen (icons, widgets, etc.) moves to the left or right by the full screen width, but the background image (or live wallpaper) only moves by a fraction of that width. My question is how get this effect. till now have done this. SurfaceHolder holder = getSurfaceHolder(); Canvas canvas = null; try { canvas = holder.lockCanvas(); if (canvas != null) { drawCircles(canvas); } } finally { if (canvas != null) holder.unlockCanvasAndPost(canvas); } the draw

Android merge two images

心已入冬 提交于 2019-12-20 04:54:08
问题 I want to merge two images and then save them on the Android SDCard.One is from the camera and one from the resources folder. The problem is that i get this error: Caused by: java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor. Thanks. Bitmap bottomImage = BitmapFactory.decodeResource(getResources(),R.drawable.blink); Bitmap topImage = (Bitmap) data.getExtras().get("data"); // As described by Steve Pomeroy in a previous comment, // use the canvas to combine them. //

Draw a line on ImageView set by Picasso

时间秒杀一切 提交于 2019-12-20 04:38:41
问题 I am trying to figure out how to simply draw a line on an image that is being set in Picasso. I found that if I simply set the image, given a URI, with Picasso and try to draw paint to it using the following: canvas = new Canvas(bitmap); image.draw(canvas); topEdge = new Paint(); topEdge.setColor(context.getResources().getColor(R.color.blue)); topEdge.setStrokeWidth(5); canvas.drawLine(c1.getX(), c1.getY(), c2.getX(), c2.getY(), topEdge); Then I get a crash saying that the bitmap needs to be

How to move image on curve on touch event in android?

不羁岁月 提交于 2019-12-20 03:54:18
问题 I have drawn a Cubic Curve on canvas using myPath.cubicTo(10, 10, w, h/2, 10, h-10); I have four ImageView on that screen and I want to move that ImageViews on the drawn curve when I drag that image with touch. I have referred the links : Move Image on Curve Path Move object on Curve Move imageview on curve What I get is, Animation to move the Image on Curve with the duration defined by t. But I want to move that ImageView on touch in direction of that curve area only. Following is my Screen