Set stroke blur for VectorDrawable - android

Is there any way to set a blur for the stroke lines in a VectorDrawable, other than drawing it twice with different strokewidths? Can I extend VectorDrawable and modify its paint?

Related

Drawing image with gradient tint and round corners

I'm trying to set a background on a view, which should be an image with a single rounded corner and a gradient tint overlayed
I feel like I'm close, I'm just missing the rounded corner. I have made a minimal working example project here: https://github.com/RandomStuffAndCode/AndroidCanvas
From https://github.com/RandomStuffAndCode/AndroidCanvas/blob/master/app/src/main/java/com/randomcodeandstuff/androidcanvas/MainActivity.java :
RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(getResources(), src);
dr.setCornerRadius(convertToPixels(context, CORNER_RADIUS));
Bitmap drBitmap = drawableToBitmap(dr);
Paint drPaint = new Paint();
drPaint.setAntiAlias(true);
drPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(drBitmap, 0,0,drPaint);
This obviously gives me 4 rounded corners instead of just 1. I considered drawing a rectangle on top of the other rounded corners, but because of the gradient overlay this does not look good.
How do i get rid of the 3 other rounded corners? Screenshot of the code here:
If you're targeting API level 21+, a possible option would be to use a normal ImageView, but set an ViewOutlineProvider on it. The Outline you provide will probably have to be the convexPath option, so you'd have to tinker with that for your specific use-case.

Set Background Image for a Shape drawn by Canvas

The goal is to draw some hexagons on the screen and set different background images for those hexagons (I'm making a broad game). I have read about the Shape in XML file, but i want to draw it programmatically. I have drawn a shape with the help of canvas like this:
Path hexPath = hex.getPath();
canvas.clipPath(hexPath);
canvas.drawColor(Color.RED);
how can i set up the background image for this shape ?
I also have read about cropping a Bitmap, but is not practical for me.
Thanks.

Draw Custom Shape

How I can draw this type of shape and change color in runtime
I am referring this Making a triangle shape using xml definitions? but its not giving as expecting result
Use 9 patch image For that.
9 patch image
Or Here you can make that shape Direct,
Draw trapezoid shape

How to correctly extract highlights and shadows from a grayscale image

I am drawing some buttons on the screen. Each with a different color, but the same shape, designed in Photoshop with all sort of reflections and shines.
I want to use a single bitmap of the shape and change its color programmatically, preserving all the reflections and shadows. This is what I do right now:
Get the shape into a ARRGB_8888 bitmap (even though all colors are shades of gray)
Copy the bitmap pixels to 3 buffers: Image, Highlights, Shadows
The reference grayshade is RGB[128,128,128]
In the Highlights buffer, zero all pixels below the reference (+ threshold)
In the Shadows buffer, zero all pixels above the reference (- threshold)
From the Highlights and Shadow buffers create Highlights and Shadow Bitmaps
Draw the original grayscale image using a PorterDuffColorFilter on mode MULTIPLY
Draw on top the shadows, using the Shadows bitmap and XferMode DARKEN
Draw on top the highlights, using the Highlights bitmap and XferMode LIGHTEN
I do get a result, but I realize that the final button color is not the target color, but a darker shade of it, because the MULTIPLY mode with a reference of 128 cuts all components in half.
I tried to set the reference to a whiter shade of gray, but then the highlights get saturated.
I tried to use SRC_IN on step 7 above, and I get the target color only on areas that are neither highlights nor shadows.
See the results:
Not sure what I need to ask, but I want to get the buttons with the exact target color and its highlights and shadows. Maybe I am generating the Highlights and Shadows masks wrong, or maybe I am using the wrong blending modes. Or maybe it is something else.

How to draw alpha on an image / setting pixels invisible - on fingertouch

I want to create a little scratch game. The problem is, that I can't figure out how to erase pixels from an image in android (like the eraser in gimp / photoshop).
The image is an .png with alpha channel.
AIUI, drawing operations on a canvas blend a transparent pixel with the prior value of the pixel. This is by default, and you can see it by setting a canvas to black and drawing a fully transparent shape onto it, and then drawing the underlying bitmap over an image of another canvas (result: a fully black canvas), or by setting a canvas to a partially transparent color and, drawing a shape of another partially transparent color, and then drawing this over an image (result: the original image is tinted by the first color, outside the shape; within the shape, it's tinted by both transparent colors). I don't know the blending method used by default, and looking through the docs just makes me wish I knew what book to buy so I can understand how to use what's available.
So I would set pixels to transparent by setting them 'directly', with Bitmap methods, rather than with canvas operations. Although if you need to punch a transparent shape into an overlay, you can draw the shape with a solid non-transparent color, and then manipulate the bitmap directly, mapping this color to the transparent color.
Bitmap docs. Prefer getPixels() and setPixels() to a method-call per pixel.
EDIT: ...er, did I misunderstand? You want to 'erase' pixels as in a paint program? Then just draw whatever the background color is. There's no erasure involved.

Categories

Resources