android-canvas

Canvas' drawLine and drawRect not including end position?

天大地大妈咪最大 提交于 2019-12-09 08:21:59
问题 To my surprise I've just discovered that drawLine and drawRect don't include the ending position, i.e.: canvas.drawLine(100, 100, 100, 100, paint); or RectF rect = new RectF(100, 100, 100, 100); canvas.drawRect(rect, paint); won't draw anything. My paint is defined as follows: Paint paint = new Paint(); paint.setAntiAlias(false); paint.setStyle(Paint.Style.FILL); return paint; I've tried defining my paint as FILL_AND_STROKE, but it wouldn't help. Android's drawPaint() javadoc don't even list

Rotate Text in Canvas

一曲冷凌霜 提交于 2019-12-09 07:16:15
问题 How do you rotate text that is in the canvas? I need to flip the text I have upside down. paint.setTextSize(20); canvas.drawText("3AM", xStored, yStored, paint); 回答1: I got the solution from the comment by Romain Guy below the accepted answer How can you display upside down text with a textview in Android? Quoting You can just scale by -1 on the Y axis. @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int cx = this.getMeasuredWidth() / 2; int cy = this.getMeasuredHeight(

Android Paint PorterDuff.Mode.CLEAR

不打扰是莪最后的温柔 提交于 2019-12-09 06:12:37
问题 I'm working on application which is drawing on Canvas similar to Finger Paint demo from Android SDK. My problem is when I'm using PorterDuff.Mode.CLEAR . When drawing and Canvas and if I try to erase something, it's working fine. But if I try to save my image as PNG file the strokes of eraser are coloured black, and I'm not sure why is this happening. Here is an example what I'm doing : @Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.WHITE); canvas.drawBitmap(mBitmap,

Drawing over a view and all it's children

邮差的信 提交于 2019-12-09 05:23:13
问题 I'm trying to apply a visual effect to a viewgroup. My idea is to grab a bitmap of the viewgroup, shrink it down, expand it back up, and draw it over the viewgroup to give it a blocky, low quality effect. I've got most of the way there using this code: public class Blocker { private static final float RESAMPLE_QUALITY = 0.66f; // less than 1, lower = worse quality public static void block(Canvas canvas, Bitmap bitmap_old) { block(canvas, bitmap_old, RESAMPLE_QUALITY); } public static void

Drawing a line following finger - motionevent.getX() and getY() incorrect UPDATE

廉价感情. 提交于 2019-12-09 02:05:04
问题 UPDATE: please read entire question again :-) Background: I have created a grid of dots by creating a custom view and then adding these views to a TableLayout . The aim is for me to be able to draw a line from one of these dots to another dot in a way so that when a dot is pressed, a line is started from the center of the pressed dot to the point where the finger is currently touching. When the finger is dragged over another dot, the line then finishes at the center of that dot. The result

ZoomView canvas matrix Android

元气小坏坏 提交于 2019-12-08 23:16:14
问题 I'm implementing a zoomable View from examples I've found on Stack and other websites. I do want to add a drawing feature to the view. I'm able to get the paths to show up but the scaling is way off from the image behind it. I used an example android image where I traced along the shape and the paths appeared to the left and above it. Also, zooming causes it to shift (pictures below). I've been playing around with the onDraw method where the canvas is drawn but with little success. I

is canvas in android proportional on different devices

末鹿安然 提交于 2019-12-08 22:33:51
问题 I am trying to make an app using canvas and a surfaceview, and I am worrying that in the future I would have many problems with it because I am not sure if the canvas is proportional with every device. currently I can only use my emulator since my phone's usb cable doesn't work(I know.. I have to get a new one..). anyways, i would like to know if the canvas would transfer my coordinates and make everything proportional, what I mean by that is that if i have something in point a, lets say (10,

Error : RuntimeException at DisplayListCanvas.throwIfCannotDraw

时光怂恿深爱的人放手 提交于 2019-12-08 14:59:58
问题 My application work very well on nougat emulator and many devices, but i found this exception in google play crash reporter, I don't know why it happened, The exception causes with nougat devices ++ only. the exception : java.lang.RuntimeException: at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260) at android.graphics.Canvas.drawBitmap(Canvas.java:1420) at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545) at android.view.View

Canvas OnDraw method

邮差的信 提交于 2019-12-08 11:42:21
问题 I am currently creating a maze using a pair of boolean array (horizontal and vertical) in order to draw lines for the maze. The maze only every displays 5 bools from the array at one time. Then, I have an user who is always centered and as he moves through the maze the next set of bools are drawn. This is working as it should. The issue that I am having is: when the user moves to a certain part of the maze the for loop drawing the lines becomes higher than the bool array and therefore crashes

Drawing text on a scaled Canvas

不问归期 提交于 2019-12-08 10:25:14
问题 I'm having a problem drawing text on a canvas that has been scaled. I want to scale the canvas so that drawing dimensions and co-ordinates are always in the range 0.0 to 1.0 i.e. independent of Canvas width and height. (If this is poor practice please feel free to comment giving a reason why this is so.) While I can draw lines and arcs on a scaled canvas correctly, I'm having great difficulty painting text and this problem only seems to occur on Android 4.2 As an example, I have created some