I want to rotate an ImageView programmatically in my Activity. Currently I couldn\'t find any solutions for Xamarin which works and translated solutions from Android didn\'t wor
The line
Bitmap bMap = BitmapFactory.DecodeResource(Resources, Resource.Id.imageView1);
Is where your app will fail. Why? The Resource Id you are passing in is not for an actual image, but for the ImageView
instance. DecodeResource is used for decoding images and not views.
Instead you should do something like:
var drawable = image.Drawable;
using (var bitmap = Bitmap.CreateBitmap(drawable.IntrinsicWidth, drawable.IntrinsicHeight, Config.ARGB_8888))
using(var canvas = new Canvas(bitmap))
{
drawable.SetBounds(0, 0, canvas.Width, canvas.Height);
drawable.Draw(canvas);
var mat = new Matrix();
mat.PostRotate(45);
using(var bMapRotate = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, mat, true))
image.SetImageBitmap(bMapRotate);
}