I need to rotate an ImageView by a few degrees. I'm doing this by subclassing ImageView and overloading onDraw()
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.scale(0.92f,0.92f);
canvas.translate(14, 0);
canvas.rotate(1,0,0);
super.onDraw(canvas);
canvas.restore();
}
The problem is that the image that results shows a bunch of jaggies.
http://img.skitch.com/20100608-gmdy4sexsm1c71di9rgiktdjhu.png
How can I antialias an ImageView that I need to rotate in order to eliminate jaggies? Is there a better way to do this?
Set antialias and filterBitmap to the paint that draw's the bitmap. I had a similar problem and this worked for me:
I did the following to get it to work:
In
AndroidManifest.xml
I enabled hardware-acceleration<application android:hardwareAccelerated="true">
.Instead of using a custom draw-method, I changed the layer-type of the parent-view to hardware-accelerated with anti-aliasing enabled and added my subviews as follows:
I have to add that clipping cannot be disabled when using this approach.
@Primoz990's solution worked for me :) I also enabled Dithering, so my final code which removes the jagged edges on rotation is this:
If you know that your Drawable is a BitmapDrawable, you can use anti-aliasing in the bitmap's Paint to do something like the following:
This rotation solves just one part of problem - jagged edges, but the image instead became wierd.
ifound only one solution yet: in ondraw or dispatch draw method