# DrawtoBitmap with my own created RhinoViewport - c# RhinoCommon

**URL:** <https://discourse.mcneel.com/t/drawtobitmap-with-my-own-created-rhinoviewport-c-rhinocommon/38831>\
**Category:** Rhino Developer\
**Tags:** rhinocommon\
**Created:** [November 16, 2016, 7:35pm UTC](https://discourse.mcneel.com/t/drawtobitmap-with-my-own-created-rhinoviewport-c-rhinocommon/38831 "2016-11-16T19:35:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![namarcin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/namarcin/32/564250_2.png) [@namarcin](https://discourse.mcneel.com/u/namarcin)\
**Post date:** [November 16, 2016, 7:35pm UTC](https://discourse.mcneel.com/t/drawtobitmap-with-my-own-created-rhinoviewport-c-rhinocommon/38831/1 "2016-11-16T19:35:44Z")

</div>

Hi,  
It’s possible to draw own created `RhinoViewport` with `DisplayPipeline.DrawToBitmap` method to Bitmap?  
With standard Rhino Viewports DrawToBitmap works perfect, but when I create my own viewport then DrawToBitmap return null bitmap.

```
RhinoViewport rviewport = new RhinoViewport();
Bitmap vportBitmap = DisplayPipeline.DrawToBitmap(rviewport,200,200);
```

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [November 16, 2016, 8:26pm UTC](https://discourse.mcneel.com/t/drawtobitmap-with-my-own-created-rhinoviewport-c-rhinocommon/38831/2 "2016-11-16T20:26:45Z")

</div>

Hi Marcin,

Can you explain a little bit more details about what you want to do and why? What problem are you trying to solve?

Thanks,

– Dale

---

<div class="post-metadata">

**Author:** ![namarcin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/namarcin/32/564250_2.png) [@namarcin](https://discourse.mcneel.com/u/namarcin)\
**Post date:** [November 16, 2016, 8:38pm UTC](https://discourse.mcneel.com/t/drawtobitmap-with-my-own-created-rhinoviewport-c-rhinocommon/38831/3 "2016-11-16T20:38:27Z")

</div>

I want to generate a preview Image of i.e MeshObject, something like Preview in MaterialEditor.  
I draws the object on Viewport through DisplayConduit:

```
if(Viewport.Id == MyViewport.Id)
{
DrawMesh(myMesh);
}

```

The problem is that when I call the method `DrawToBitmap (MyViewport)` then return null Bitmap.

---

<div class="post-metadata">

**Author:** ![namarcin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/namarcin/32/564250_2.png) [@namarcin](https://discourse.mcneel.com/u/namarcin)\
**Post date:** [November 17, 2016, 7:38pm UTC](https://discourse.mcneel.com/t/drawtobitmap-with-my-own-created-rhinoviewport-c-rhinocommon/38831/4 "2016-11-17T19:38:44Z")

</div>

Hi,  
I found a simple solution (maybe not elegant) just simply create a InstanceDefinition from object, then create preview with `InstanceDefinition.CreatePreviewBitmap`. After create bitmap simply purge InstanceDefinition from InstanceDefinitionTable.

```
  List<Rhino.DocObjects.ObjectAttributes> objattrs = new List<Rhino.DocObjects.ObjectAttributes>();
            List<Rhino.Geometry.GeometryBase> geometries = new List<Rhino.Geometry.GeometryBase>();

            Rhino.DocObjects.ObjectAttributes objattr = new Rhino.DocObjects.ObjectAttributes();
            objattr.ObjectColor = System.Drawing.Color.Red;
            objattrs.Add(objattr);
            geometries.Add((Rhino.Geometry.GeometryBase) new Rhino.Geometry.Torus(Rhino.Geometry.Plane.WorldXY,100,PenSize.Value.Value).ToNurbsSurface());

            int idefindex = Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions.Add("for preview", "preview image", new Rhino.Geometry.Point3d(0, 0, 0),geometries, objattrs);

        previewBitmap = `Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions[idefindex].CreatePreviewBitmap(DefinedViewportProjection.Perspective, Rhino.DocObjects.DisplayMode.RenderPreview, new System.Drawing.Size(200,200));`

```

🙂

---

<div class="post-metadata">

**Author:** ![MatrixRatrix](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/matrixratrix/32/529711_2.png) [@MatrixRatrix](https://discourse.mcneel.com/u/MatrixRatrix)\
**Post date:** [January 28, 2022, 6:25pm UTC](https://discourse.mcneel.com/t/drawtobitmap-with-my-own-created-rhinoviewport-c-rhinocommon/38831/5 "2022-01-28T18:25:19Z")

</div>

Hello

Sorry realive

sorry to revive this topic.

I’m using this method to extract small images from some objects;

Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions[idefindex].CreatePreviewBitmap(DefinedViewportProjection.Top, Rhino.DocObjects.DisplayMode.Shaded, ponto,true)

Does anyone know how I can create the bitmap without isocurves and with the object’s color?

This my orignal:

 ![Original](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/e/3/2/e32c1b8ed3cc70b51e5a3ab0d949467c71ed1623.jpeg)

This is the Bitmap result:  
 ![test](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/d/b/a/dba7c3ea1bb36c1b6cfd17586e467ffa5204a868.png)

Thanks

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [February 2, 2022, 4:53pm UTC](https://discourse.mcneel.com/t/drawtobitmap-with-my-own-created-rhinoviewport-c-rhinocommon/38831/6 "2022-02-02T16:53:26Z")

</div>

Hi @MatrixRatrix,

Turn off the object’s isocurves before capturing.

– Dale

---

<div class="post-metadata">

**Author:** ![MatrixRatrix](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/matrixratrix/32/529711_2.png) [@MatrixRatrix](https://discourse.mcneel.com/u/MatrixRatrix)\
**Post date:** [February 2, 2022, 5:34pm UTC](https://discourse.mcneel.com/t/drawtobitmap-with-my-own-created-rhinoviewport-c-rhinocommon/38831/7 "2022-02-02T17:34:08Z")

</div>

> [@namarcin](#):
>
> `Rhino.DocObjects.DisplayMode`

Hello @dale

Can I make my own DisplayMode just for this CreatePreviewBitmap?  
Rhino.DocObjects.DisplayMode

Thanks

---

<div class="post-metadata">

**Author:** ![MatrixRatrix](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/matrixratrix/32/529711_2.png) [@MatrixRatrix](https://discourse.mcneel.com/u/MatrixRatrix)\
**Post date:** [February 2, 2022, 6:09pm UTC](https://discourse.mcneel.com/t/drawtobitmap-with-my-own-created-rhinoviewport-c-rhinocommon/38831/8 "2022-02-02T18:09:24Z")

</div>

> [@dale](#):
>
> Hi @MatrixRatrix,
> 
> Turn off the object’s isocurves before capturing.
> 
> – Dale

Sorry @dale

How do I convert DisplayModeDescription to DisplayMode?

 ![create](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/8/7/a87874e9768c785ba44d1b560e084c9df73498fb.jpeg)

Thanks
