I am trying to rotate a bitmap in a RemoteViews. However when I use either of the Matrix.setRotate methods or either of the Matrix.postRotate methods the Bitmap gets scaled wierd. Here is the code I am using to accomplish the task.
Bitmap bMap = BitmapFactory.decodeResource(context.getResources(), R.drawable.arrow);
Matrix m = new Matrix();
m.setRotate((float) 0, bMap.getWidth()/2, bMap.getHeight()/2);
bMap = Bitmap.createBitmap(bMap,0,0, bMap.getWidth(),bMap.getHeight(),m, true);
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.speedometer);
remoteView.setImageViewBitmap(R.id.speedoNeedle, bMap);
Here is the original layout file xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="136px"
android:layout_height="136px"
>
<ImageView
android:layout_width="136px"
android:layout_height="136px"
android:src="@drawable/dial"
/>
<ImageView
android:id="@+id/speedoNeedle"
android:layout_width="9px"
android:layout_height="78px"
android:layout_marginLeft="63px"
android:layout_marginTop="27px"
android:rotation="-138"
android:src="@drawable/arrow" />
</RelativeLayout>
If I set the rotate value to zero or comment out the m.setRotate((float) 0, bMap.getWidth()/2, bMap.getHeight()/2) the bitmap displays correctly.
If i set the rotation value to 138 I get this: you can barely see the needle.
Here is a screenshot of the value at 184:
The needle isn't even visible at the max value of 276.
What am I doing wrong? How can I fix it?
Thanks in advance.