Android View setRotation causes artifacts - android

If I set the rotation to a view, there will be some artifacts on the margin of the view.
How can I fix this?
I use view.setRotation.

You probably need to enable anti-aliasing. If you're using Paint to draw on a Canvas, you can achieve this by calling Paint.setAntiAlias(true). However, if you're drawing a Bitmap, you need to set a 1px transparent border around your Bitmap

Related

Android Draw SVG Path on canvas with animation

I have a SVG path and Paint to draw path on canvas and I used
canvas.drawPath(path.getSvgPath(), path.getSvgFillPaint()); it is work properly and now I want to add animation when fill path with given Paint. loke Happy Color App Happy Color
if you have a any idea please reply this.
thank you
Use a timer or thread or Animate class to change what path.getSvgFillPaint's fillOpacity gradually down to 0.
Every time when the fillOpacity changes, call View's postInvalidate to redraw the canvas, you will see it fade out gradually.

Drawing outside canvas on android drawable

I am trying to draw shadow on my drawable, but the shadow gets cropped, since the rectangle I am drawing is the size of canvas.getClipBounds().
In order to draw the shadow I set the hardware acceleration on the view
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
And I also set the Shadow Layer in my Custom Drawable
bgPaint.setShadowLayer(radius, 0, 0, Color.Black);
When I draw a small rectangle the shadow is rendered. So, I know my original problem is about the shadowing being discarded for being outside of the canvas.
I tried some approaches, such as:
Setting the Drawable's bounds,
Increasing the canvas' bounds,
Disable clipChildren on the parent view,
Overriding Drawable.getPadding()
But none of them helped me.

create shadow for bitmap in custom view

I have a custom view wich contain some bitmaps and I want to set shadows for them, for that, I use this code:
shadowPaints=new Paint(Paint.ANTI_ALIAS_FLAG);
shadowPaints.setShadowLayer(10.0f, 3.0f, 2.0f, Color.BLACK);
canvas.drawBitmap(bmp, matrix, shadowPaints);
setLayerType(LAYER_TYPE_SOFTWARE, shadowPaints);
and my result is
as you can see my shadow actually is another bitmap with different x and y position but what I want is my shadow be a solid color
bitmap.
can anyone help me about this?
setShadowLayer is actually meant for putting shadows on text.
If you already know the bitmap you want to draw, you can just add a shadow in PhotoShop and draw the bitmap and shadow all at once.
If you don't want to do that, you could make a shadow by making a copy of the image, using a PorterDuff filter to make it all grey, use Renderscript to blur the image, and draw it on the canvas at an x,y offset before drawing the actual image on top of it.
Personally, I think PhotoShop is a lot easier.

change canvas size for TextView

I need use TextView with outline text. I try use it: https://stackoverflow.com/a/10294290/4181010 , but it doesn't work correctly with android:layout_width="wrap_content", because it doesn't increase canvas when add outlines.
I need to increase the canvas to include the value of strokeWidth.
I suggest I have to override onMeasure somehow, but TextView call final method setMeasuredDimension at the end of onMeasure to apply view size and I can not intervene at this point so as not to have to rewrite the whole method.
Scaling the canvas in OnDraw does not work either, because TextView scales draw text with canvas.
My solution is increase canvas and use canvas.translate() to move in right position before draw text.
And my question: How can I increase the size of the canvas with minimal intervention? Or someone know another solution for this problem?
I'm guessing you are drawing the text twice, once with the orange (manually on the canvas) and once with the white (what the TextView is drawing with super.onDraw).
Instead of drawing the larger orange manually, you could instead draw the smaller white text and leave the orange text to TextView's super.onDraw. That way everything should fit within the canvas.

Is it possible to show bitmap in a parallelogram shape?

Normally, when you draw a bitmap to the canvas, it is rectangular. Is it possible to make it appear as a parallelogram instead?
Try canvas.skew(20, 0). That skews the drawing matrix in x, but you can obviously do y as well, depending on what you need.

Categories

Resources