ondraw

Clearing canvas with Canvas.drawColor()

那年仲夏 提交于 2019-11-28 21:34:07
i'm attempting to change the background image of a custom View with some success. the image will change but the problem is that i still see traces of the old image. when i attempt to clear the canvas before drawing the new image, it doesn't appear to work. i create a bitmap to store the image. when changing the image, i call Canvas.drawColor() before drawing the new image but the old image persists. i've tried drawColor(0), drawColor(Color.BLACK), c.drawColor(0, PorterDuff.Mode.CLEAR), and none of the above works. as such, i had to post this for review from more experienced minds than mine.

How to animate gradient?

时间秒杀一切 提交于 2019-11-28 17:19:49
How to animate gradient from color#1 to color#2? Something similar to I'm planning to use it as health-bar for unit (so, it will be finit animation starting with green and ending with red) Nexen While googling it, I found 2 ways to do it for android: use ShaderFactory or extends View, using new Shader(new LinearGradient()) . Both answers do the same - calling new Shader() every View.onDraw(Canvas canvas) method's call. Its really expensive if number of such animated gradients more than ~3. So I did it another way. I avoided calling new every onDraw() , using single precalculated LinearGradient

Android custom view Bitmap memory leak

血红的双手。 提交于 2019-11-27 18:50:53
I've got a custom view in which I need to draw two bitmaps, one is a background, representing the image of a map and one is a pin which will be drawn on top/left position in canvas. The both images are drawn onDraw and remain the same during the live of the activity that contains the view. After a while I get a OutOfMemoryError: bitmap size exceeds VM budget This means that I have a leak and the bitmaps don't get garbage collected. I asked this question before, but now the situation changed a little. I made a init method where I set the bitmaps I want to use but this still isn't a good

Clearing canvas with Canvas.drawColor()

我的未来我决定 提交于 2019-11-27 13:56:12
问题 i'm attempting to change the background image of a custom View with some success. the image will change but the problem is that i still see traces of the old image. when i attempt to clear the canvas before drawing the new image, it doesn't appear to work. i create a bitmap to store the image. when changing the image, i call Canvas.drawColor() before drawing the new image but the old image persists. i've tried drawColor(0), drawColor(Color.BLACK), c.drawColor(0, PorterDuff.Mode.CLEAR), and

PorterduffXfermode: Clear a section of a bitmap

隐身守侯 提交于 2019-11-27 12:22:18
The goal is simply to draw a bitmap and over the top of it draw shapes that ERASE the underlying area of the bitmap. I have created simple proof of concept code to try and understand how exactly I should go about this. In the various threads here I have found numerous hints about using: android.graphics.PorterDuff.Mode.CLEAR The code below simply creates a screen with a blue background and adds a custom view. This view draws on its canvas a pink background, the bitmap image (with a slight border to show the pink background), and yellow overlaying circles representing each PorterDuffXfermode.

How to animate gradient?

故事扮演 提交于 2019-11-27 10:11:10
问题 How to animate gradient from color#1 to color#2? Something similar to I'm planning to use it as health-bar for unit (so, it will be finit animation starting with green and ending with red) 回答1: While googling it, I found 2 ways to do it for android: use ShaderFactory or extends View, using new Shader(new LinearGradient()) . Both answers do the same - calling new Shader() every View.onDraw(Canvas canvas) method's call. Its really expensive if number of such animated gradients more than ~3. So

Android Multiple SurfaceViews

微笑、不失礼 提交于 2019-11-27 07:01:30
I'm trying to work with 3 SurfaceViews on one screen, one on top half (BoardView), one on bottom half (StatusView), and the last one as an extra layer above the top half (TileView) (see main.xml). I created a class MySurfaceView, which is extended by BoardView, StatusView and TileView. I've got multiple problems with this. Let me first give the code. main.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/main_background"> <com

How to draw Arc between two points on the Canvas?

泪湿孤枕 提交于 2019-11-26 21:43:16
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. 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, -(float) sweepAngle, true); To calculate startAngle , use this code: int startAngle = (int) (180 / Math.PI

Android custom view Bitmap memory leak

回眸只為那壹抹淺笑 提交于 2019-11-26 19:37:30
问题 I've got a custom view in which I need to draw two bitmaps, one is a background, representing the image of a map and one is a pin which will be drawn on top/left position in canvas. The both images are drawn onDraw and remain the same during the live of the activity that contains the view. After a while I get a OutOfMemoryError: bitmap size exceeds VM budget This means that I have a leak and the bitmaps don't get garbage collected. I asked this question before, but now the situation changed a

PorterduffXfermode: Clear a section of a bitmap

巧了我就是萌 提交于 2019-11-26 16:02:41
问题 The goal is simply to draw a bitmap and over the top of it draw shapes that ERASE the underlying area of the bitmap. I have created simple proof of concept code to try and understand how exactly I should go about this. In the various threads here I have found numerous hints about using: android.graphics.PorterDuff.Mode.CLEAR The code below simply creates a screen with a blue background and adds a custom view. This view draws on its canvas a pink background, the bitmap image (with a slight