How to draw the Bitmap onto only one of the RhinoViewports?

Hi community! I want to use the DisplayPipeline.DrawSprite() Method to draw a Bitmap onto only one of my RhinoViewport.

I’ve read this post: Rhino - Display Conduits ( It indeed provides some pretty useful code snippet, and I successfully use the code to draw a Bitmap on to all the RhinoViewports.

I find that the Conduit Class doesn’t have any API for me to draw onto only one viewport.
So here is the code snippet that I tried to draw the Bitmap onto only one of my RhinoViewport, but it doesn’t work well:

RhinoView myRhinoView;
Bitmap bmp;
bool run;

     DisplayPipeline ppl = myRhinoView.DisplayPipeline;
     DisplayBitmap d_bmp = new DisplayBitmap(bmp);
     int width = myRhinoView.MainViewport.Bounds.Width;
     int height = myRhinoView.MainViewport.Bounds.Height;

     ppl.DrawSprite(d_bmp, new Point2d(width/2, height/2), width, height);

Can anyone lend me a hand?

The event handlers all get DrawEventArgs Class which has DrawEventArgs.Viewport Property . Check that and if it isn’t the viewport you want to draw in just do an early exit without any drawing.

1 Like

It works!
Here is my code:

protected override void PostDrawObjects(DrawEventArgs e)
    if (e.Viewport.Name == DrawSprite.rhinoView.MainViewport.Name)
        DisplayBitmap d_bmp = new DisplayBitmap(DrawSprite.bmp);
        int width = DrawSprite.rhinoView.MainViewport.Bounds.Width;
        int height = DrawSprite.rhinoView.MainViewport.Bounds.Height;
        DisplayPipeline ppl = DrawSprite.rhinoView.DisplayPipeline;
        ppl.DrawSprite(d_bmp, new Point2d(width / 2, height / 2), width, height);

I have another question and I will create a new topic. Thank you!