android-canvas

Change color without affecting anything previously drawn

别说谁变了你拦得住时间么 提交于 2019-11-26 17:20:23
问题 I have the following CustomView I am using for painting in my app: package com.test.testing; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Paint.Style; import android.view.MotionEvent; import android.widget.TextView; public class CustomView extends TextView { Paint paint; Path path; float x = 0; float y = 0; private int cWhite = Color.WHITE; public CustomView

Android canvas: draw transparent circle on image

末鹿安然 提交于 2019-11-26 17:09:40
I am creating a pixel-hunting game. So my activity shows an ImageView. And I want to create a hint "show me where is the object". For this I need to blur whole image except a circle around a point where the object is located. Instead of blur I can show a just semitransparent black background. There is there is no problem to draw a semitransparent rectangle on the Canvas. But I don't know how to crop a transparent circle from it. The result should look like like this: Please help me to achieve same result on Android SDK. Robert So finally I managed to do this. Firstly I draw a semitransparent

Measuring text height to be drawn on Canvas ( Android )

不羁的心 提交于 2019-11-26 16:59:01
Any straight forward way to measure the height of text? The way I am doing it now is by using Paint's measureText() to get the width, then by trial and error finding a value to get an approximate height. I've also been messing around with FontMetrics , but all these seem like approximate methods that suck. I am trying to scale things for different resolutions. I can do it, but I end up with incredibly verbose code with lots of calculations to determine relative sizes. I hate it! There has to be a better way. bramp What about paint.getTextBounds() (object method) Suragch There are different

Android: How to do this framing paint?

时间秒杀一切 提交于 2019-11-26 16:03:47
问题 I Have Some static images like below: Now, I want is, when i touch on the face or hand, then the selected color should be fill on that skin portion. See below image of result: So how to get the result like above ?? Redo and Undo Functionality Should be also there. I have try with the FloodFill color but doing that i can only able to do color in to the perticular portion. as FloodFill only fill the color till the same pixwl color comes. If the touch place pixel color get change the it will not

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

Hex Colors in Android are some times 8 digits. How? What is the difference between #FFFFFF and #FFFFFF00

人盡茶涼 提交于 2019-11-26 15:57:00
问题 I sometimes have seen in examples where the coloring in Android is done as #FF191919. I mean a 8 digit hex number . But it should be only a 6 digit number. How are they related? If I want o convert a 6 digit number to a 8 digit number. How to do it? I mean convert #424242 to a 8 digit number coloring? Please let me know the details. Thank you for your time and help. 回答1: The extra 2 digits are used to define the colors transparency, or alpha channel. Android uses the ARGB format (or AARRGGBB

Using clipRect - explanation

隐身守侯 提交于 2019-11-26 15:45:27
问题 public class POCII extends Activity { myView mv = new myView(this); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(mv); } } class myView extends View { public myView(Context context) { super(context); } @Override public void onDraw(Canvas canvas) { Paint paint = new Paint(); canvas.drawRect(0,0,100,100, paint); canvas.clipRect(0,0,50,50); } } My question is, shouldn't the above code draw a rectangle and then crop the top left

Android canvas draw rectangle

我们两清 提交于 2019-11-26 15:44:30
how to draw empty rectangle with etc. borderWidth=3 and borderColor=black and part within rectangle don't have content or color. Which function in Canvas to use void drawRect(float left, float top, float right, float bottom, Paint paint) void drawRect(RectF rect, Paint paint) void drawRect(Rect r, Paint paint) Thanks. I try this example Paint myPaint = new Paint(); myPaint.setColor(Color.rgb(0, 0, 0)); myPaint.setStrokeWidth(10); c.drawRect(100, 100, 200, 200, myPaint); It draws rectangle and fill it with black color but I want just "frame" around like this image: pandur Try paint.setStyle

Get Canvas coordinates after scaling up/down or dragging in android

北城以北 提交于 2019-11-26 15:36:04
问题 I'm developing an application in which I'm pasting images, doing drawing and painting on canvas. This app can also Scale up/down the canvas or drag it to different location. My problem is: I can't get the correct canvas coordinates after scaling or dragging the canvas. I want to draw finger paint after the canvas is scaled or dragged but unable to retrieve the right place where i've touched..:( Also I'm new bee. Here is the code. @Override public void onDraw(Canvas canvas) { super.onDraw

Android: How to check if a path contains touched point?

拜拜、爱过 提交于 2019-11-26 15:28:41
问题 i would try to develop an application in which i can draw a planimetry. So, each room has got its own ID or name and, if i touch a room, i want to show a Toast Message with that ID or name. The problem is how check if and which path is touched!! I saw a lot of topic discussions that talked about this problem. Someone says to use getBounds method and, after, contains method for checking if touched point is in Rect. But, i guess getBounds method returns the smallest Rect that contains path,