drawn circle is not the same size as a drawn bitmap

66 Views Asked by At

I have been trying to code collision for a school project, however I quickly noticed that when I draw a bitmap using the canvas.DrawBitmap(currentImage, position.X, position.Y, paint) function, it did not match the size of the radius, as the image appeared bigger then the actual circle. this is not an issue when i use the canvas.DrawCircle(position.X, position.Y, size.Width / 2, new Paint() { Color = Color.Black }) function, as it is scaled properly. How do I create a bitmap that is scaled correctly to the actual circle?

  • relevent code:

      public Sprite(float x, float y, float size, Context context) : base(x, y)
      {
          int id = (int)typeof(Resource.Drawable).GetField(General.IMG_BALL).GetValue(null);
          image = BitmapFactory.DecodeResource(context.Resources, id);
          this.size = new SizeF(size, size);
          paint = new Paint(PaintFlags.AntiAlias);
          paint.AntiAlias = false;
          paint.FilterBitmap = false;
          paint.Dither = true;
          paint.SetStyle(Paint.Style.Fill);
      }
    
      public void DisplayImage(Canvas c)
      {
          Matrix matrix = new Matrix();
          matrix.PostTranslate(position.X, position.Y);
          matrix.PreScale(size.Width, size.Height);
          c.DrawBitmap(image, matrix, paint);
      }
    
  • results using canvas.DrawCircle(position.X, position.Y, size.Width / 2, new Paint() { Color = Color.Black }) (correct scaling, no bitmap, radius = 100): screenshot

  • results using the DrawImage(canvas) function I made (wrong scaling, using bitmap, radius = 1 so it can fit in the image) screenshot

0

There are 0 best solutions below