Forum Xamarin.Android

Draw on Png Background

Hi. I'm brand new to Xamarin (and mobile development) and have a bit of a challenging task ahead of me.

I need to take a map (eastern seaboard of a country) and add data to it. The data is added by including transparent rectangles above cities, and in those rectangles, including certain text (being the data - numbers and text).

This is currently implemented in a Java application for desktop machine and we want to port it to Android and iOS.

A quick search of the doco turns up something called Skiasharp. Is that the only drawing API for Xamarin Android? If not, which is the recommended API for something like what I need to accomplish?

I found doco on System.Drawing, but it looks like that is just iOS. Is that the case?



Best Answer


  • onefootswillonefootswill AUMember ✭✭

    OK. So I discarded the idea of SkiaSharp because there's not much out there on it and the Xamarin sample is not classic Xamarin. (Spent a whole morning trying to get somewhere with SkiaSharp. Not fun.)

    I started going OK by making a class which inherited from View, which gave me a Canvas to work with via the OnDraw handler.

    It blows up at this line:
    canvas.DrawRoundRect(100, 100, 400, 400,10, 10, paintC);
    with the error message "Java.Lang.NoSuchMethodError: no method with name='drawRoundRect' signature='(FFFFFFLandroid/graphics/Paint;)V' in class Landroid/graphics/Canvas;"

    Is there a problem with DrawRoundRect? Any reason it should be chuckin a nah nah?

    The whole code for the OnDraw handler is:

        protected override void OnDraw(Canvas canvas)
            canvas.DrawBitmap(BitmapFactory.DecodeResource(Resources, Resource.Drawable.east_coast), 0, 0, null);
            // custom drawing code here  
            Paint paint = new Paint();
            paint.TextSize = 160.0F;
            // make the entire canvas white  
            paint.Color = Color.Blue;
            Paint paintRectangle = new Paint();
            // make the entire canvas white  
            paintRectangle.Color = Color.Blue;
            canvas.DrawText("Here is some text", 55, 155, paint);
            canvas.DrawRoundRect(100, 100, 400, 400,10, 10, paintRectangle);
            //// draw blue circle with anti aliasing turned off  
            //undo the rotate  
  • onefootswillonefootswill AUMember ✭✭

    Thanks very much Matthew. Your sample app was exactly what I was after. The biggest thing I struggled with was the axml. Your sample looks pretty straight forward and I'll look at implementing that kind of thing in my app.

    I'll let you know how I get on.

Sign In or Register to comment.