android-canvas

Implementing an eraser in an Android drawing app - black trail and then transparent

情到浓时终转凉″ 提交于 2019-11-30 02:04:33
I have an drawing app for Android and I am currently trying to add a real eraser to it. Before, I had just used white paint for an eraser, but that won't do anymore since now I allow background colors and images. I do this by having an image view underneath my transparent canvas. The problem that I am facing is that whenever I enable my eraser, it draws a solid black trail while I have my finger down, but once I release it goes to transparent. See the screen shots below: This is how it looks while my finger is on the screen - a solid black trail This is what it looks like once I remove my

Understanding how actually drawRect or drawing coordinates work in Android

ぐ巨炮叔叔 提交于 2019-11-29 23:21:42
I am trying to draw a rectangle over a canvas and I am facing troubles to understand the in-depth of rectangle draw of Android. I've read tutorials and every possible but I am stuck. Here in the image , the red rectangle is my target. Irrespective of any rectangle size I need to draw the red rectangle bit above the base and in the middle of the rectangle. The worst nightmare I am facing here is understanding the X,Y Width and Height coordinates. Can anyone explain how that math works, sometime we go up , Y reaches to very small but same width coordinates are higher. And I am never able to

how to make full circular image view in android [duplicate]

天涯浪子 提交于 2019-11-29 22:31:02
Possible Duplicate: How to make an image fit into a circular frame in android I want a 360 degree circular shape Image View, I found related solutions on stackoverflow, but they were all yielding rounded corners in image view. But i want full circular image view. For rounded corners image view links are: Rounded corners in imageView How to make an ImageView with rounded corners? Any thoughts. Get the Bitmap: Bitmap bitmap = getthebitmapyouwanttoshowinacirclefromsomewhere; Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Use a shader:

Android: draw arc within canvas api with a gradient fill color

与世无争的帅哥 提交于 2019-11-29 21:44:25
问题 I want to draw an arc using canvas using a gradient fill. How can achieve this? 回答1: Hey I stole this from here: Draw an arc with a SweepGradient in Android but it works fine, I used a LinearGradient instead. Shader gradient = new SweepGradient (0,getMeasuredHeight()/2, Color.RED, Color.WHITE); lightRed.setShader(gradient); canvas.drawArc(rectf, -90, 360, false, lightRed); 回答2: In my cause i I had to draw someone like this: Maybe you too. So, let's think! How does Sweep Gradient works? If you

Looking for an explanation of post/pre/set Translate (in Matrix object) and how to use them

折月煮酒 提交于 2019-11-29 19:49:14
The documentation is pretty vague as to what is actually happening when these methods are used. Can someone explain how Matrix actually affects the Bitmap that it's being set to? They use the term concatenate in there, but I'm unclear on how that term applies to coordinate data (having only used it in regard to string manipulation before). The set-methods will replace the current Matrix with new values, disregarding whatever the Matrix contained before. The pre and post method will apply a new transformation before or after whatever the current Matrix contains. In this example, the rotation

How to make any view to draw to canvas?

陌路散爱 提交于 2019-11-29 19:44:23
I have a short question: Suppose I have a (mutable) bitmap that I need to modify (add images, texts, etc...) . Instead of messing around with many special classes for drawing to the canvas (paint, canvas, matrices and so on), I was thinking why not use the built in classes of Android for this task and only if i need really customized operations i could still use the canvas ? So, for example, in order to show any kind of view (that has no parent, of course) on the bitmap, I could call the next function : public void drawViewToBitmap(Bitmap b, View v, Rect rect) { Canvas c = new Canvas(b); // <=

Android UnsupportedOperationException at Canvas.clipPath

不想你离开。 提交于 2019-11-29 17:51:53
问题 I am using the image crop library from here https://github.com/lvillani/android-cropimage in my project to crop images stored on device. However, certain users are reporting crashes with the following stack trace java.lang.UnsupportedOperationException at android.view.GLES20Canvas.clipPath(GLES20Canvas.java:413) at com.android.camera.HighlightView.draw(HighlightView.java:101) at com.android.camera.CropImageView.onDraw(CropImage.java:783) at android.view.View.draw(View.java:11006) at android

Clear canvas in button click

自古美人都是妖i 提交于 2019-11-29 17:47:23
I used following code to draw. I want to clear the previously drawn lines if the clear button is clicked. public class MainActivity extends Activity { private ArrayList<Path> _graphics = new ArrayList<Path>(); private Paint mPaint; Activity activity; View mView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); activity = this; mView = new DrawingView(this); activity.addContentView(mView, new LayoutParams(500, LinearLayout.LayoutParams.WRAP_CONTENT)); init(); } public void clear(View v) { new DrawingView

How to draw a bitmap to another, but into a given quadrilateral (not necessary a rectangle)?

。_饼干妹妹 提交于 2019-11-29 17:21:12
Suppose I have 2 bitmaps. One is smallBitmap, and one is largeBitmap. I want to draw the entire smallBitmap into largeBitmap, but only to a part of largeBitmap, and not in a straight regtangle, but into a quadrilateral instead. I think a sketch will best describe what I mean: An example of this scenario is a tilted smartphone image (like this or this ), that you need to put a screenshot into its screen. The input is: smallBitmap, largeBitmap, "quadrilateral" coordinates of the largeBitmap (where to put the smallBitmap). The "quadrilateral" of the largeBitmap just has 4 coordinates and it's not

Technique to make a canvas drawLine() clickable?

大城市里の小女人 提交于 2019-11-29 16:44:30
I'm working on an app that plots nodes on a map, and each node has edges that are represented by a line between them. I've drawn the edges using Canvas and drawLine(), but it would be useful if the lines themselves could be clickable. By that I mean a method of allowing the user to touch the line or think they're touching the line and an event can trigger. (like display edge info, etc...) I can't rightly attach a touch event to a line I've drawn with Canvas, so I was thinking of placing ImageViews inbetween the ends of each edge line that's drawn. The ImageView could be a dot so it's clear