Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload CreateImage to support numpy (RGBA uint8) images #402

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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