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.
Related
I want to draw with canvas a radius on top of middle like below
How can I draw a radius like I marked on picture
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?
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.
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
How can i draw path with translucent (semi-transparent) band on canvas (method onDraw in my custom View)? I draw path line by bezier curve (method path.quadTo), but i want to around the line was illuminated translucent band?
I tried several approaches:
Try draw path by paint with semi-transparent color 0x8800ff00.
Try use paint.setShader(new BitmapShader(semi-transparent background image)) and draw path by this paint;
But they did not help. There was no effect of translucency.
Does it work if you first draw the curve using a Paint with a much bigger StrokeWidth and a transparent color (this being the glow), then draw your first curve on top of it?