# how to output a vtkTextureObject as jpg, png, bmp, etc?

**URL:** https://discourse.vtk.org/t/how-to-output-a-vtktextureobject-as-jpg-png-bmp-etc/11806
**Category:** Support
**Created:** [June 24, 2023, 4:07pm UTC](https://discourse.vtk.org/t/how-to-output-a-vtktextureobject-as-jpg-png-bmp-etc/11806 "2023-06-24T16:07:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![gpu](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/e47c2d/32.png) [@gpu](https://discourse.vtk.org/u/gpu)
#### Post date: [June 24, 2023, 4:07pm UTC](https://discourse.vtk.org/t/how-to-output-a-vtktextureobject-as-jpg-png-bmp-etc/11806/1 "2023-06-24T16:07:19Z")

</div>

how to output a vtkTextureObject as jpg, png, bmp, etc? there is not api in vtkTextureObject can do this. thanks!

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 24, 2023, 9:33pm UTC](https://discourse.vtk.org/t/how-to-output-a-vtktextureobject-as-jpg-png-bmp-etc/11806/2 "2023-06-24T21:33:05Z")

</div>

Hello,

I can think of one dirty way to do it. `vtkTextureObject` has the overloaded `CopyToFrameBuffer()` method ([https://vtk.org/doc/nightly/html/classvtkTextureObject.html#a3801bf2e51d41a5cc9f617146a1685b2](https://vtk.org/doc/nightly/html/classvtkTextureObject.html#a3801bf2e51d41a5cc9f617146a1685b2)) you can use to copy the texture’s fragments as pixels to the OpenGL’s frame buffer (used to contain the rendered pixels). Then, you can use some method based on OpenGL calls to save the frame buffer’s pixels as some image file: [c++ - Save OpenGL rendering to an image file - Stack Overflow](https://stackoverflow.com/questions/59234281/save-opengl-rendering-to-an-image-file) . After you save the image, just command another render to restore the original rendered scene.

take care,

PC

---

<div class="post-metadata">

### Author: ![gpu](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/e47c2d/32.png) [@gpu](https://discourse.vtk.org/u/gpu)
#### Post date: [June 25, 2023, 2:08am UTC](https://discourse.vtk.org/t/how-to-output-a-vtktextureobject-as-jpg-png-bmp-etc/11806/3 "2023-06-25T02:08:47Z")

</div>

Thanks! thought VTK already had API for this 😆  
there is no way to get vtkImageData or other things from vtkTexture to directly save out?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 25, 2023, 12:33pm UTC](https://discourse.vtk.org/t/how-to-output-a-vtktextureobject-as-jpg-png-bmp-etc/11806/4 "2023-06-25T12:33:25Z")

</div>

You’re quite welcome! There is a more elegant way to do it I think. You can use `vtkTextureObject`’s `GetHandle()` method to get its OpenGL handle id. Then use it with non-rendering OpenGL calls to save it to a file: [save texture to a file - OpenGL: Basic Coding - Khronos Forums](https://community.khronos.org/t/save-texture-to-a-file/62340)

best,

PC
