DisplayPipeline.DrawBitmap Method (DisplayBitmap, Int32, Int32)

DisplayPipelineDrawBitmap Method (DisplayBitmap, Int32, Int32)

Draws a bitmap in screen coordinates

Namespace:  Rhino.Display
Assembly:  RhinoCommon (in RhinoCommon.dll)
Syntax
public void DrawBitmap(
	DisplayBitmap bitmap,
	int left,
	int top
)
Public Sub DrawBitmap ( 
	bitmap As DisplayBitmap,
	left As Integer,
	top As Integer
)

Parameters

bitmap
Type: Rhino.DisplayDisplayBitmap
bitmap to draw
left
Type: SystemInt32
where top/left corner of bitmap should appear in screen coordinates
top
Type: SystemInt32
where top/left corner of bitmap should appear in screen coordinates
Examples
using System.Drawing;
using Rhino;
using Rhino.Commands;
using Rhino.Display;

namespace examples_cs
{
  public class DrawBitmapConduit : Rhino.Display.DisplayConduit
  {
    private readonly DisplayBitmap m_display_bitmap;

    public DrawBitmapConduit()
    {
      var flag = new System.Drawing.Bitmap(100, 100);
      for( int x = 0; x <  flag.Height; ++x )
          for( int y = 0; y < flag.Width; ++y )
              flag.SetPixel(x, y, Color.White);

      var g = Graphics.FromImage(flag);
      g.FillEllipse(Brushes.Blue, 25, 25, 50, 50);
      m_display_bitmap = new DisplayBitmap(flag);
    }

    protected override void DrawForeground(Rhino.Display.DrawEventArgs e)
    {
      e.Display.DrawBitmap(m_display_bitmap, 50, 50, Color.White);
    }
  }

  public class DrawBitmapCommand : Command
  {
    public override string EnglishName { get { return "csDrawBitmap"; } }

    readonly DrawBitmapConduit m_conduit = new DrawBitmapConduit();

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // toggle conduit on/off
      m_conduit.Enabled = !m_conduit.Enabled;

      RhinoApp.WriteLine("Custom conduit enabled = {0}", m_conduit.Enabled);
      doc.Views.Redraw();
      return Result.Success;
    }
  }
}
Imports System.Drawing
Imports Rhino
Imports Rhino.Commands
Imports Rhino.Display

Namespace examples_vb
  Public Class DrawBitmapConduit
    Inherits Rhino.Display.DisplayConduit
    Private ReadOnly m_display_bitmap As DisplayBitmap

    Public Sub New()
      Dim flag = New System.Drawing.Bitmap(100, 100)
      For x As Integer = 0 To flag.Height - 1
        For y As Integer = 0 To flag.Width - 1
          flag.SetPixel(x, y, Color.White)
        Next
      Next

      Dim g = Graphics.FromImage(flag)
      g.FillEllipse(Brushes.Blue, 25, 25, 50, 50)
      m_display_bitmap = New DisplayBitmap(flag)
    End Sub

    Protected Overrides Sub DrawForeground(e As Rhino.Display.DrawEventArgs)
      e.Display.DrawBitmap(m_display_bitmap, 50, 50, Color.White)
    End Sub
  End Class

  Public Class DrawBitmapCommand
    Inherits Command
    Public Overrides ReadOnly Property EnglishName() As String
      Get
        Return "vbDrawBitmap"
      End Get
    End Property

    ReadOnly m_conduit As New DrawBitmapConduit()

    Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
      ' toggle conduit on/off
      m_conduit.Enabled = Not m_conduit.Enabled

      RhinoApp.WriteLine("Custom conduit enabled = {0}", m_conduit.Enabled)
      doc.Views.Redraw()
      Return Result.Success
    End Function
  End Class
End Namespace
Python
import Rhino
from Rhino.Geometry import *
import System.Drawing
import Rhino.Display
import scriptcontext
import rhinoscriptsyntax as rs

class CustomConduit(Rhino.Display.DisplayConduit):
    def __init__(self):
      flag = System.Drawing.Bitmap(100,100)
      for x in range(0,100):
        for y in range(0,100):
          flag.SetPixel(x, y, System.Drawing.Color.Red)
      g = System.Drawing.Graphics.FromImage(flag)
      g.FillEllipse(System.Drawing.Brushes.Blue, 25, 25, 50, 50)
      self.display_bitmap = Rhino.Display.DisplayBitmap(flag)

    def DrawForeground(self, e):
      e.Display.DrawBitmap(self.display_bitmap, 50, 50, System.Drawing.Color.Red)

if __name__== "__main__":
    conduit = CustomConduit()
    conduit.Enabled = True
    scriptcontext.doc.Views.Redraw()
    rs.GetString("Pausing for user input")
    conduit.Enabled = False
    scriptcontext.doc.Views.Redraw()
Version Information

Rhino for Mac

Supported in: 5.4

Rhino for Windows

Supported in: 6.14
See Also