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?
Related
I'm working on an APP in Android and needs to draw things on a Canvas. I want to draw a Path that is hollow, for example something like this image below.
View Image
The Path may contains lines, arcs, bezier curves, etc.
Is there a way for me to achieve that?
I had tried to draw the Path with a thicker Paint first and draw the Path again with a transparent and thinner Paint. But the problem is: there may be other things drawn on the Canvas. Doing so will cover other things intersecting with the Path.
I had also tried to translate the Canvas and draw the Path twice for the two borders. But it turned out that this will not work, for example a parabola (as shown below, it is not what I expected).
View Image
I had tried to draw the Path with a thicker Paint first and draw the Path again with a transparent and thinner Paint. But the problem is: there may be other things drawn on the Canvas. Doing so will cover other things intersecting with the Path.
What do you mean? If the first path-line covers other things drawn, it's ok the inner line would also. If the first line does not cover anything the 2nd line won't cover either.
When do you face the issue of having the first line not cover something while the thinner line does?
Picture 1 depicting path to draw. Picture 2 depicting the final result
This is a bit more of a geometry-inside-java question. Basically, I want to round a single corner of a square I drew on a canvas, sometimes it's on the top left, other times on the top right, or bottom left or right. How could a shape like the red highlight be drawn and filled using Android's drawing methods? I've read the drawing tutorials on Oracle, but I can't still figure out how to draw something like that in that position. Any help would be greatly appreciated.
I would like to draw in Android something like shape in the picture. I have used Path.drawArc but I can't draw two arcs which are parts of cirlces with the same center. Another problem is how to draw two lines which connect these arcs. In iOS I would use bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:
How to draw shape like in the sketch?
here is simple example using canvas and bitmaps, try this example and get some idea for your requirement. image cropping and transparent
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.
Animation:
All the animations on the Android books I read are made on an existing image. They load an image on the SD card and use animation functions (like alpha, scale, translate and rotate) to make it move. However, what if I want to make the shapes I drew move on the screen. For example, I just draw a circle on the screen and want to make it move from left to right. How can I do this?
Painting:
Functions like drawCircle can draw complete geometric shapes but I just want to draw part of a shape, for example, a 3/4 solid circle. How should I do? If I use drawArc, there will be a 'V' recess on the circle and I want it to be flat.