I drew some colorful balls using OvalShape and RadialGradient. Here are the result:
All balls are good, except that the black ones look like flat. How to draw a shining black ball in Android? Thanks in advance.
The other ones look really good.
For the black balls, use dark grey instead of black. With the gradient in place it will look correct.
Related
I really need help.
How can I draw such animation like the one shown in the image?
The ring should be transformed into a solid circle.
I see you comment, you don't need to know the color of background, just draw a ring with canvas.drawArc rather than drawCircle
I want to apply the border to this custom view shape
which created by many canvas.draw...() in onDraw()
The border that i want to create and apply to my custom view should have equal range all the way with some distance from the custom view and it should also cover small circle in each slice.
Any idea how to make this?
Thanks.
This isn't so much an answer, but more of a recommendation. Take a look at the Porter-Duff modes available to you. Worst case you may need to do some per pixel image manipulation which should be fine as long as the view isn't animated.
On second thought, here's an idea: why not create two images: one large circle which will always draw behind everything and a second which will always draw behind the small circles. The large circle would just be the complete border you want displayed, whereas the small circles would actually only be a semi circle border, which would render on top of the large circle (covering the large circle border under it). The key would then be to rotate the small border circle depending on where it's located. I hippie that makes sense, but it should work and be very efficient too.
Another option would be to separate the rendering into white circles and slightly larger border color circles. If you render the slightly larger (border color) circles first, then render the normal circles (white) on top, then you won't have to worry about any rotations and it will render correctly if the small outer circles begin to overlap.
So the idea is similar to the first suggestion. You'll still need a large circle and small circle (both white), but in addition, you'll need slightly larger border colored large and small circles.
I hope this description is a little clearer, but I assume that you are comfortable enough with compound drawables to figure out the rest, given that you've gotten this far in making your view.
All the best implementing it, and feel free to ask for any clarification! :)
I need to create the painting application for the kids where kid can colour inside the black bordered sketch of any image
But, I am struck with the problem,that colouring can come outside the black bordering of the image...which i don't want to.Please guys help me to find out how to restrict the colouring by user within the black border of sketch
Also, I want that no colour should cover the black border.it should be inside the border.
I can post my code if required.
Look at Canvas clipPath and use the clipping built in to android to limit the 'coloring' of the kid/user to the regions you specify. You can then draw your objects as layers, kid/user colored layer on bottom, your sketch on top.
Finally..i have implemented it using mask bitmap and right usage of Portet.Duff mode
I'm developing a game for Android. For the purpose of this question let's assume that I have a sprite of a red ball moving in space over some background or whatever.
I have a PNG file which I use to draw my background and a PNG file which I use to draw my ball over the background. The problem is my ball is a red circle on a 20 X 20 pixels PNG, meaning I have some white 'left over', so when I draw it on the screen, the 'white left over' appears over my background when I only want the red circle to.
I'm sorry but I'm totally new to animation. How do I crop my circle out of my square PNG or otherwise make the background in my ball PNG transparent? Do I do it programmatically or is there a way to paint my PNG so the non-relevant part is transparent?
Programs like Photoshop and GIMP allow you to set the background as transparent instead of white. Try editing your PNG in one of these and removing the white.
I suggest you use Paint.NET. You can use the magic wand to select the area you want to make transparent and then press "cut" (the scissor symbol) or press Ctrl + X.
I'm trying out the android graphics classes.
I wanted to draw some arcs/circles with a fill color and black outline.
The Paint class has a style for FILL_AND_STROKE, but there doesn't seem to be a way to set the fill color vs. stroke color. So as far as I can tell it's the same as FILL?
So what's the point of FILL_AND_STROKE if you can't set a separate fill and stroke color?
I haven't managed to find a good explanation.
(I solved my simple problem by doing a fill first, then a stroke, naturally)
Edit:
I ran into this bug report: http://code.google.com/p/android/issues/detail?id=4086
Comment 4 and 5 seem to imply that FILL_AND_STROKE is basically the same as FILL and it will be 'fixed' in 2.2. I guess they'll add a new color?
afaik: FILL fills your circle, while FILL_AND_STROKE also draws the border. If you increase the size of the stroke, it should result in different circles sizes (only visual!)
Think about this: you draw a circle by hand with a small sized pencil. The radius is what you wanted. If you now take a big brush and draw the circle again, your radius is much bigger... (i hope its understandable O.o )
I guess the FILL_AND_STROKE is particularly useful, if one would animate between STROKE and FILL, while wanted to retain the size of the drawn object.
I'm giving an example with the first one below is animated between FILL_AND_STROKE to STROKE, while the second is on just FILL to STROKE. You could easily see the size shrink.
Hence FILL_AND_STROKE is pretty handy here to make size as consistent as possible with others that have STROKE, without have to manually adjust the size of the drawn object (which is complicated)
Yes it's a bit silly. The only use for it is if you want to change between a stroke only and a filled circle then you can use FILL_AND_STROKE to keep the size of the circle the same.
If you went from STROKE to FILL you would lose the width of the stroke when you drew the circle again.
If your stroke style is something other than a solid line (eg a dashed line), you should be able to see the difference. Not that it seems a very useful feature though.
Being able to extend the silhouette of something (more complex than a circle) outwards can be extremely useful though, and not easily obtained by other means
Please see #Shurane's comment.
Just draw it twice, one filled, one stroke and each with one color.
Worked great for me, and gives the impression of a STROKE and a FILL!