How would you do this in canvas drawing - android

How would you draw something like this programmatically in a ondraw method? I know how to draw lines or squares, but to have an image inside a squarebox that has an arrow, is kind of confusing for me
Thank you

Just break the drawing up in different elements:
a gray box
a white rounded rectangle
a white rectangle
a blue rectangle
a blue rounded rectangle
a blue triangle
a red heart (I would just try to find a font with a nice heart)
the text in white.
Draw it all to the canvas in this order and you are fine.

Related

Semi transparent bitmap overlay renders wrong colour

I have a stack of bitmaps that I need to render one above the other. I achieve this with a relative layout and several ImageViews on top of each other which all have a Bitmap assigned to it.
This works great, but when the top layers is semi-transparent, the colours of the lower bitmap are off.
All my bitmaps use Config.ARGB_8888.
Say the top layer is red with an alpha of 50% and the bottom layer is green with an alpha of 100%.
I can either set the colour of the bitmap to red, then the alpha of the ImageView to 0.5f and it will render the green colour below fine (darker green with some red mixed in).
If I set the bitmap pixels to a 50% red like this: bmp.eraseColor(0x7Fff0000); and leave the imageView alpha on 100%, the green below will be displayed as yellow, mixing red and green, rather than overlaying it.
Unfortunately I can not use the (working) fist version because the alpha on the Bitmap above is not going to be uniform.
Is there a blend mode setting to use true colours when using semi transparent pixels in a Bitmap?
EDIT: I have also tried to set several PorterDuffXfermodes to the ImageViews but none gives the right result.
Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(Mode.MULTIPLY)); //OVERLAY//ADD//SCREEN//DARKEN//LIGHTEN
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, paint);
Got it, needed to premultiply the alpha to get the desired result.

Canvas drawText with gradient color

Is that possible to draw text on Canvas with gradient color in Andorid?
For example, draw letter A with top part is red while bottom part is blue?
Thanks

Draw smooth transparent line

I am trying to draw smooth line following my finger. The problem is in superposition. Left example is array of drawLine, and right is drawPath. Is it way to make it like smooth left example?
Construct the line as a solid color, then wrap that line inside of a drawable. Turn this drawable transparent, and then draw it to the screen.

How can i show a rectangle on the map?

I want to draw a rectangle on the map. The rectangle has a button and a shape and a text.
I can draw a rectangle on the map but when i move my finger on the screen, the size of rectangle changed.Why? I don't know how can i put a button and text and shape on the map. Please help me.

Android, canvas: How can I draw transparent circle without overprinting?

Stage 1. I have a background
Stage 2. I apply an overlay to background with a canvas to draw. First I fill the whole area with canvas.drawColor(Color.argb(128,0,0,0))
Then I need to draw a red transparent circle with color.argb(128,255,0,0) at a specified place, but I want circle red transparency replaced black filling transparency, not added. So, I wanna get this
but NOT this
How can I get it?
You can try to use Canvas.clipPath before filling area with black color to exclude area, which will be used later by circle.

Categories

Resources