Rounded intersection Android Canvas - android

I'm new to Android canvas. I'm cutting Canvas using .ClipPath(path). in the path I used lineTo() method to add all the lines. now I need to the rounded corners of all corners like Pic-2. How can I do that?

Related

android draw custom shape in circle on canvas

I am trying to draw the following shape in a circle on a canvas. I know how to draw a circle using the center, radius and paint variable. But I am trying to draw the figure below.

how to draw custom custom circle inside rectangle shape using custom view in android

how to draw custom custom circle inside rectangle shape using custom view.after drawing it should be expand the rectangle shape when ever you drag the edges of that rectangle.how to draw custom custom circle inside rectangle shape using custom view.after drawing it should be expand the rectangle shape when ever you drag the edges of that rectangle
You need to use drawRect, drawOval/drawArc for this. Read more from here:
http://developer.android.com/reference/android/graphics/Canvas.html

How to create a circle clippath from an image?

Imagine that I have a rectangle image. How could I create a style like the next one?
I mean, cropping the image into a circle, add the border, the shadow and the gross /shine effect. Until now, I only have tried this snippet code to crop the image: Cropping circular area from bitmap in Android but just that. I have no idea how to do the remaining components in Android.
An easy way to achieve this effect is to use Canvas.drawCircle() and a BitmapShader:
BitmapShader s = new BitmapShader(myPhoto, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint p = new Paint();
p.setShader(s);
myCanvas.drawCircle(centerX, centerY, radius, p);
To do the shadow, simply call Paint.setShadowLayer() on the paint (this will only work if you draw the effect into an offscreen Bitmap or if your View uses a software layer – set by calling View.setLayerType() –).
The border can be drawn by drawing another circle on top, using the Paint.Style.STROKE style (that you can set by calling Paint.setStyle()).
Finally you can draw the gloss by drawing a circle, oval or Path on top of your very first circle. You'll need to use a LinearGradient shader on your paint and you'll also need to clip the gloss. You can do this in two ways:
If you are drawing the entire effect into a Bitmap, which is what I would recommend, simply set the paint's Xfermode to a new PorterDuffXfermode(PorterDuff.Mode.SRC_IN).
If you are drawing the effect directly on screen you can simply use Canvas.clipPath() to set a circular clip. Note that this will work with hardware acceleration only as of Android 4.3.

Drawing translucent shapes without overlapping

I am drawing several circles with transparency. The number of circles and their positions are not fixed. Currently I am setting the transparent color in a Paint object and drawing the circles in a for loop with the Canvas object. But that causes overlapping.
I have thought of a method:
- Render all the circles as opaque on something other than the main canvas.
- Set the transparency.
- Draw the final object on canvas.
How do i implement that on android?
Create a new bitmap with ARGB888, and draw on it's canvas all your shapes with no transparency.
Then draw the new bitmap into the main canvas using a Paint on which you called setAlpha earlier

Android - Extend a Bitmap to use as MapMarker

I want to use downloaded images as markers on a MapView. I images are all squares but I would like the bottom to also extend to form a triangle marking the exact point.
My approach was to create a canvas which is slightly larger than the image. Then, draw the bitmap on to the canvas and then somehow pick the color from the bottom of the bitmap and draw a triangular shape from the horizontal center of the image to the bottom of the canvas. Something like this...
As you might guess I'm stuck with the last part. So far I have....
Bitmap canvasBitmap = Bitmap.createBitmap(markerBitmap.getWidth(), markerBitmap.getHeight()+10, Bitmap.Config.ARGB_8888);
// The 10 pixels will be the so called "pin"
Canvas canvas = new Canvas(canvasBitmap);
canvas.drawBitmap(markerBitmap, 0.0f, 0.0f, null);
// Can figure out how to draw the 10 px bottom using the color from markerBitmap
Help !!
Is there any specific reason why you want to create the images dynamically? If not, why don't you create them using a graphics editing program, save them as png's or 9-patch images and then simply assign it to the Drawable that's used for the marker.

Categories

Resources