# Render text to RenderWindow or vtkUnsignedCharArray directly

**URL:** https://discourse.vtk.org/t/render-text-to-renderwindow-or-vtkunsignedchararray-directly/9143
**Category:** Support
**Tags:** python, code
**Created:** [August 13, 2022, 6:28pm UTC](https://discourse.vtk.org/t/render-text-to-renderwindow-or-vtkunsignedchararray-directly/9143 "2022-08-13T18:28:33Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![rdbrn](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rdbrn/32/5627_2.png) [@rdbrn](https://discourse.vtk.org/u/rdbrn)
#### Post date: [August 13, 2022, 6:28pm UTC](https://discourse.vtk.org/t/render-text-to-renderwindow-or-vtkunsignedchararray-directly/9143/1 "2022-08-13T18:28:33Z")

</div>

I’m making an interactive measuring tool for an interactor.

The interactor draws a line between the two points by setting the pixel values in a vtkUnsignedCharArray (in very much the same way as the rubberband zoom)  
That works fine,

now I want to add the measured distance to the line.

I found vtkFreeTypeTools and RenderString to render the string to a vtkImageData object.

So I think I’m almost there.

Last thing I need is a way to get the data out of the ImageData object and into either the RenderWindow or the vtkUnsignedCharArray

I’m working in Python, the code so far is:

```python
def DrawLine(self, x1, x2, y1, y2):
        rwi = self.GetInteractor()
        rwin = rwi.GetRenderWindow()

        size = rwin.GetSize()

        x1 = min(max(x1,0), size[0])
        x2 = min(max(x2,0), size[0])
        y1 = min(max(y1,0), size[1])
        y2 = min(max(y2,0), size[1])

        tempPA = vtkUnsignedCharArray()
        tempPA.DeepCopy(self._pixel_array)

        xs, ys = self.LineToPixels(x1, x2, y1, y2)
        for x, y in zip(xs, ys):
            id = (y * size[0]) + x
            tempPA.SetTuple(id, (0, 0, 0, 1))

        # and Copy back to the window
        rwin.SetRGBACharPixelData(0, 0, size[0] - 1, size[1] - 1, tempPA, 0)

        # can we add something to the window here?
        freeType = vtk.vtkFreeTypeTools.GetInstance()
        textProperty = vtk.vtkTextProperty()
        textProperty.SetJustificationToLeft()
        textProperty.SetFontSize(24)
        textProperty.SetOrientation(25)

        textImage = vtk.vtkImageData()
        freeType.RenderString(textProperty, "text", 72, textImage) # this does not give an error, assume it works

        # Now put the textImage in the RenderWindow
        # rwin.SetRGBACharPixelData(0, 0, size[0] - 1, size[1] - 1, textImage, 0)

        rwin.Frame()

```
