android-canvas

Android Drawing Fill Tool

烂漫一生 提交于 2019-12-07 03:48:02
问题 I am making a drawing app for android and I need some help adding a fill tool. I want the tool to flood fill, and to behave like it would in Microsoft Paint, but on a phone. I have a custom view that draws a path on a canvas. I draw different paths for different pens and brushes, and I allow users to pick line thickness and color. When I do: paint.setStyle(Paint.Style.FILL); and I paint, I don't get a fill how I want. I have gotten some suggestions to use the "Flood Fill Algorithm", but I can

rotate dial in limited degrees

六眼飞鱼酱① 提交于 2019-12-06 23:56:10
问题 All I want rotate image in particular angle as like below image. I have code for rotation but it rotate 360 degree but I want it only for particular degrees and get the selected number which is upper side of dial. below is my code. My custom View this work fine but lake of perfomance. import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PointF; import

Android Paint setShadowLayer() ignores color of its Paint

Deadly 提交于 2019-12-06 21:24:04
问题 I'm trying to create a Bitmap programmatically and am finding drawing a shadowed Rect is ignoring the color arg passed in. I've simplified things down to this case - the code just draws a rotated blue square which is supposed to have a grey shadow, but the shadow is always blue: main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill

Android get bounds of rotated,scaled text on canvas

人盡茶涼 提交于 2019-12-06 16:49:31
问题 I have a textview with some text. Textview have touch events, so user can rotate, scale and translate text. For translation, rotation and scaling i'm using canvas. Canvas is doing this inside onDraw() function. Now i want to have outer bounds of text when it is scaled or rotated, can anybody help me. Thanks in Advance. I try this piece of code to translate,rotate and scale text on canvas: canvas.scale(fScaledFactorForTextview,fScaledFactorForTextview,getTextWidth() / (2.0f * getLineCount()) +

Two layers, but can't show the bottom layer in android

强颜欢笑 提交于 2019-12-06 16:49:20
I am working on an Android project similar to a scratch card. I have two layers in RelativeLayout. Bottom layer contains an ImageView, and top layer contains a SurfaceView. The problem is the display stays black and doesn't show the ImageView even if I set canvas.drawColor(Color.TRANSPARENT) . What should I do if I want to scratch and erase the part of SurfaceView and reveal the ImageView below? Thanks in advance. And I am sorry for the bad English. Here's my layout: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android

Android inverse clip

£可爱£侵袭症+ 提交于 2019-12-06 15:34:08
问题 I need to specify a rectangle in which the Android canvas CANNOT draw inside of. I know that clipRect will specify and area in which to draw in, but I was if I could reverse this effect. In other words how do I draw an object making it draw to the outside of a rectangle. Image for clarification: 回答1: I'm not sure if this is actually going to be more performant than doing an overdraw. But you could set a clipping path to the full view, then set a second one to the exclusion zone with Region.Op

Draw Rectagle with fill outside bounds

老子叫甜甜 提交于 2019-12-06 15:03:36
I am drawing an Rectangle with outside of rectangle fill. I tried some of this. But cant get the perfect one what i expected. This is what i expected. I tried Point pTopLeft = new Point(); Point pBotRight = new Point(); pTopLeft.x = 100; pTopLeft.y = 100; pBotRight.x = canvas.getWidth() - 100; pBotRight.y = canvas.getHeight() - 100; Rect above = new Rect(0, 0, canvas.getWidth(), pTopLeft.y); paint.setColor(Color.parseColor("#77000000")); canvas.drawRect(above, paint); Rect left = new Rect(0, pTopLeft.y, pTopLeft.x, pBotRight.y); paint.setColor(Color.parseColor("#77000000")); canvas.drawRect

Make Screen Compatibility Containing Canvas

吃可爱长大的小学妹 提交于 2019-12-06 15:01:36
I am working with canvas in android. i want to draw shapes on canvas which fits in every screen. if screen size is 320 * 240 then height & width with is 90 * 90 but if screen_size is > 320 * 240 then it should increase accordingly. Suppose screen_size = 1280 * 800 then how much it should increase I don't know what to do for this Code is Like int fixHeight = 240, fixWidth = 320; Paint paint; paint = new Paint(); paint.setColor(Color.GREEN); DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int height = displaymetrics

Draw a hollow circle on an Android Canvas

有些话、适合烂在心里 提交于 2019-12-06 12:00:59
I am working on creating a custom view where a user can select an angle. Below is an example of what the end result should look like: I am achieving this with the following code: mPaint.setColor(Color.BLACK); canvas.drawCircle((int) (mSize.right / 2), (int) (mSize.bottom / 2), mWidthOutside, mPaint); mPaint.setColor(Color.LTGRAY); canvas.drawCircle((int) (mSize.right / 2), (int) (mSize.bottom / 2), mWidthInside, mPaint); The problem with doing it this way, is the background is a static LTGRAY , which I hope to make Transparent. How would I go about leaving the center of the circle transparent?

How to create Bitmap form Drawable object

余生长醉 提交于 2019-12-06 10:19:57
问题 I am developing custom view for android. For that I want give a user ability to select and image using just like when using ImageView In attr.xml I added bellow code. <declare-styleable name="DiagonalCut"> <attr name="altitude" format="dimension"/> <attr name="background_image" format="reference"/> </declare-styleable> In custom view I get this value as a Drawable which was provided in xml as app:background_image="@drawable/image" TypedArray typedArray = getContext().obtainStyledAttributes