Can a rectangle be filled with multiple colors.I mean using canvas drawrect method, a rectangle is drawn, and it is to be filled with 3(Example) colors. It can be done by drawing 3 different rectangles, but looking for some optimized solution.
Related
I am trying to draw two rectangles one to another but with different colours.
I am calling drawing like this:
canvas.drawRect(0,0,50,50);
canvas.drawRect(0,50,50,100);
After the rectangles are drawn I can see line tick 1px between these two rectangles.
Can you tell me what is wrong with my logic?
Is there a way by which I can draw a colored rectangle (as in shapeRenderer.filledRect() ) and attach a image to it?
I know that we can draw a Rectangle using ShapeRenderer and then SpriteBatch.draw() an image (Texture) over it.But then they are two separate objects just one drawn 'over' another.
But is there a way I can combine a rectangle and an image attached to it into one object?
I have an image view with a (not really) complex background. The background is to be the composition of three circles, each with different dynamically set colors.
one circle, the largest, is actually a perimeter (i.e. stroke)
one circle, the second largest, is concentric with the perimetric circle
one circle, the smallest, sits at the base of the other two circles (so that it is not concentric).
I successfully create the 3-circle background using layer-list. But the problem is that I am not able to change the colors in the layer-list dynamically. Changing the color of these circles is a crucial part of the design.
So since my ImageView is part of a custom view anyway, I am now thinking of using the canvas in onDraw(Canvas canvas) to create my three circles and set them as the background of the ImageView. However, the problem with this approach is that I don't know how to set my composite image (the three circles) as the background of my ImageView.
Any snippet of code solving this problem is greatly appreciated.
I have a canvas on which the background image if first drawn.
Then another image is drawn on top of the background.
I have a Gradient object that moves across the screen. The Paint used in the Gradient has its Xfermode set as,
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
The effect works but it is also applied on the background image. How can i avoid the background image from affected by the mask on top?
The paint will be applied on the whole of your Canvas. As your background is drawn using the same Canvas than the Gradient object, of course using a custom Xfermode will affect said background!
One possible solution would be to separate your background and your foreground in 2 different Canvas objects backed up by separate Bitmap objects, then merge the layers together as one would do in Photoshop. I posted a sample code that does just this on StackOverflow a while ago, here is the link to it:
https://stackoverflow.com/a/10370828/1350375
On an android Canvas, if I draw a circle with alpha 0xCC and color Color.RED and then draw another circle which partially overlaps the first circle with the same parameters, I'll end up with a venn diagram.
Here is a random example I found (just ignore the [Text] in there). I want to draw overlapping circles like in this diagram, but I don't want the center to be darker, but I do want the whole thing to have alpha so that the map underneath is visible.
Is there a way to do this directly or do I need to draw to a bitmap without alpha and then set the alpha for the whole bitmap and draw it to a canvas? (I haven't used bitmaps yet, so I am not sure how they are used yet.)
The easy way would be your suggested solution, ie. drawing all circles with no alpha to a bitmap, then draw that bitmap to another one using the desired alpha.
The hard way would be using blend modes, specifically PorterDuff.Mode in Android. An example can be found here.