Wednesday, 14 August 2013

canvas image rotation on with center like dialer

canvas image rotation on with center like dialer

I have a square shape image which having circle view, I am drawing that
image in center of circle using canvas using below code:
Bitmap bitmapCompass = BitmapFactory.decodeResource(getResources(),
R.drawable.compass_rim);
float w2= (w-bitmapCompass.getWidth())/2;
float h2= (h-bitmapCompass.getHeight())/2;
canvas.drawBitmap(bitmapCompass, w2, h2, paint);
I want to rotate this image like a dialer relative to center.Facing issue
to make rotation of Image around that circle center.
Used code for rotation:
Bitmap bitmapCompass = BitmapFactory.decodeResource(getResources(),
R.drawable.compass_back);
float w2= (w-bitmapCompass.getWidth())/2;
float h2= (h-bitmapCompass.getHeight())/2;
Matrix matbitmapCompass = new Matrix();
matbitmapCompass.postRotate((float)90);
Bitmap bmpRotateCompass = Bitmap.createBitmap(bitmapCompass, 0,0,
bitmapCompass.getWidth(), bitmapCompass.getHeight(),
matbitmapCompass, true);
canvas.drawBitmap(bmpRotateCompass, w2, h2, paint);
Help will be appreciated.
Thanks

No comments:

Post a Comment