I have two images: one that is an empty jar, and one that is the same jar but with a fill. My goal is to use a custom renderer to draw the empty jar, do a calculation of the percentage, and then copy a subset of the full jar onto the empty one to simulate the jar responsively filling based on a value. To do this, I am making a custom ImageRenderer.
I have overridden the Draw() class as follows:
public override void Draw(Canvas canvas)
{
base.Draw(canvas);
//Draw the fill
GoalJarView handle = (GoalJarView)this.Element;
int startY = (int)(canvas.Height - Math.Floor(canvas.Height * (handle.CurrentValue / handle.GoalValue)));
Rect bounds = new Rect(0, startY, canvas.Width, canvas.Height);
Bitmap bmp = BitmapFactory.DecodeResource(this.Context.Resources, Resource.Drawable.jar_fill);
canvas.DrawBitmap(bmp, bounds, bounds, null);
}
For some reason, this results in the correct image being drawn, but for whatever reason it is upside down and in the wrong place:
The weird thing is, if I change the src rectangle to null, it displays in the correct location, right-side up, but not cropped.
canvas.DrawBitmap(bmp, null, bounds, null);
Why is Android flipping this image?