[cairo] What is the c# code to draw an image as a background then draw other stuff over it?

alan battersby alan.battersby at ntlworld.com
Sat Nov 14 06:26:17 PST 2009

Thanks for the advice, I followed your suggestions and all works fine.
The problem I had with freezing seems to have gone away.

I have another slight problem. I am using a transformation between the
profile coordinates and the mouse coordinates. This depends on the
drawing area size, the max grid radius and a possible translation (as I
can pan across the grid).

During editing I pick up the mouse coordinates, and then want to use the
contexts inverse transformation to get the actual values. However as the
context is not an argument passed to the motion notify event this means
I have to save the context in my class to be used within the notify
event handler instead of having it inside a using block.

However I keep getting the following message.

Cairo.Context: called from finalization thread, programmer is missing a
call to Dispose

My question is where and how do I call the Dispose function and what is
its name.

I did this because I thought that to keep getting a context, scaling it
etc just to use the inverse transformation would be inefficient.




void DrawProfile()
    if (_grid == null)
    ct = Gdk.CairoHelper.Create (this.GdkWindow);  *** would normally have
using ( ... ) here

    // draw grid as background
    if (_editingstarted) {
        ct.Color = editingColr;
        double lw = 1.0, lh=1.0 , ld=10.0;
        ct.InverseTransformDistance(ref lw,ref lh);
        ct.LineWidth = Math.Min(lw,lh);
        Vector3 mp = posn.Vector3;
        ct.LineTo(mp.X ,mp.Y);
        ct.TextPath("Radius: " + posn.Radius.ToString());
        string a = "Angle: " + posn.Angle.ToString();
        TextExtents xa = ct.TextExtents(a);
        ct.MoveTo(mp.X,mp.Y - 2 * xa.Height);

void HandleMotionNotifyEvent (object o, MotionNotifyEventArgs args)
    if (_translateflag) {
        translateVector = new PointD(args.Event.X - startmove.X,
                                 args.Event.Y - startmove.Y);
    _grid = null;
    if (_editingstarted) {
        // userPosition needs the cairo context
        posn.Vector3 = userPosition(args.Event.X, args.Event.Y);
        _editAngle = posn.Angle;
    if (_translateflag || _editingstarted)

Vector3 userPosition(double xp, double yp)
    double x = xp;
    double y = yp;
    ct.InverseTransformPoint(ref x, ref y);
    return new Vector3((float)x,(float)y,0);

void scaleView(Context ct)
    int width =0;
    int height=0;
    float maxr = _maxGridRadius + _radialscale;
    GdkWindow.GetSize(out width,out height);
    ct.Translate(width/2, height/2);
    double scale = currentscalefactor * Math.Min(width/(2 * maxr),height/(2
* maxr));

More information about the cairo mailing list