android-canvas

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.

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

谁说胖子不能爱 提交于 2019-11-27 12:15:58
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. The extra 2 digits are used to define the colors transparency, or alpha channel. Android uses the ARGB format (or AARRGGBB as you use in your example) For more (Android-specific) information take a look at the Color documentation

How can I draw an animated view in android?

假装没事ソ 提交于 2019-11-27 11:49:29
问题 I created a custom view from scratch. Extended View and overrided onDraw() . When comes down in animating the view i generate a custom animation using offsets. eg. while(!isOnTop){ mOffset++; //draw the component a a it higher using the offset if(position == 0) isOnTop==true; invalidate(); } The thinking is that my frames come from invalidate it self. The problem is that invalidation of this view can come just by scrolling a listview at the same screen. This "shared invalidation()" causes lag

Using clipRect - explanation

拜拜、爱过 提交于 2019-11-27 11:47:00
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 portion? The rectangle is not getting cropped. Please explain what clipRect does. What is it actually

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

[亡魂溺海] 提交于 2019-11-27 11:36:20
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(canvas); canvas.save(); //canvas.translate(mPosX, mPosY); canvas.scale(mScaleFactor, mScaleFactor, super

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

巧了我就是萌 提交于 2019-11-27 11:15: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, right? So, rooms have different custom geometric forms and, for this reason, if i get bounds about 2 close

Drawing on Canvas and save image

痴心易碎 提交于 2019-11-27 11:09:27
I am new to the Android Graphics class. I want to draw an image(actually a signature kind) using the touch events and want it to be saved on SDcard when I want to save it. I have scanned through the web for any such tutorials but I have not found any. Can anyone please tell me how to draw on canvas using the touch events and save it. Any tutorials or sample code will be of great help. Belovoj I saw really good code on android developers, but I can't find it anymore... It's output is bezier curves so it will be pretty smooth. Here is code that I edited: public class MyDrawView extends View {

Android - How to circular zoom/magnify part of image?

半世苍凉 提交于 2019-11-27 10:34:32
问题 I am trying to allow the user to touch the image and then basically a cirular magnifier will show that will allow the user to better select a certain area on the image. When the user releases the touch the magnified portion will dissapear. This is used on several photo editing apps and I am trying to implement my own version of it. The code I have below does magnify a circular portion of the imageview but does not delete or clear the zoom once I release my finger. I currently set a bitmap to

Measuring text width to be drawn on Canvas ( Android )

若如初见. 提交于 2019-11-27 09:38:37
问题 Is there a method which returns the width ( in pixels ) of a text to be drawn on an Android canvas using the drawText() method according to the Paint used to draw it? 回答1: Have you looked at android.graphics.Paint.measureText(String txt)? 回答2: Paint paint = new Paint(); Rect bounds = new Rect(); int text_height = 0; int text_width = 0; paint.setTypeface(Typeface.DEFAULT);// your preference here paint.setTextSize(25);// have this the same as your text size String text = "Some random text";

How to display Text in Android Canvas ShapeDrawable with in the RectShape or OvalShape?

那年仲夏 提交于 2019-11-27 09:36:29
I'm trying to display Text in RectShape which uses ShapeDrawable to display in Canvas. I'm able to display RectShape in this code, but looking for how to display the String on that! public class CustomDrawableView extends View { private ShapeDrawable mDrawable; public CustomDrawableView(Context context) { super(context); int x = 10; int y = 10; int width = 300; int height = 50; mDrawable = new ShapeDrawable(new OvalShape()); mDrawable.getPaint().setColor(0xff74AC23); mDrawable.setBounds(x, y, x + width, y + height); } protected void onDraw(Canvas canvas) { mDrawable.draw(canvas); } } or public