Skip to content

Conversation

martinruenz
Copy link

It can be useful to open images from memory in python, for instance to show results generated with numpy.

Such functionality is implemented in this pull request by overloading the function NVGcontext.CreateImage

Usage example:

import PIL
import PIL.Image
import numpy as np
import nanogui

numpy_image = np.random.randint(0,255,[400,400,4]).astype(np.uint8) 
numpy_image[:,:,3] = 1 # Set alpha to 1

nanogui.init()
screen = nanogui.Screen((500, 500), "numpy image example", fullscreen=False)  
window = nanogui.Window(screen, "window") 
window.setLayout(nanogui.GroupLayout())

tex_id = screen.nvgContext().CreateImage(numpy_image, 0)
image_view = nanogui.ImageView(window, tex_id)

screen.setVisible(True)
screen.performLayout()
nanogui.mainloop()

@svenevs
Copy link
Collaborator

svenevs commented May 25, 2019

$ resources/check-style.sh
Error: found the following coding style problems:
    python/nanovg.cpp:124:                                                   py::array::forcecast>& image, int flags){
    python/nanovg.cpp:125:                  if(image.ndim() != 3 || image.shape(2) != 4)
The command "resources/check-style.sh" exited with 1.

It wants spaces: ){ -> ) { and if( -> if (

The example is nice, but do be careful not to create one ever frame ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants