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

Any chance to display an image? #49

Open
JokerQyou opened this issue Jan 9, 2016 · 5 comments
Open

Any chance to display an image? #49

JokerQyou opened this issue Jan 9, 2016 · 5 comments

Comments

@JokerQyou
Copy link

Like popup quick view window for an image in memory, rather than saving it to disk before programmatically open it via "Preview" app. Is that possible now? Or would you consider implementing this feature?

@daredoes
Copy link
Collaborator

You can do this by using StringIO for the file contents. I do this to generate QR Codes that pop-up in preview. I've made a PR to add this functionality #89

@JokerQyou
Copy link
Author

JokerQyou commented Nov 30, 2018

I took a look at your PR, and it seems to be previewing an image on disk. I was initially thinking about directly previewing an image in memory, like by directly transforming an BytesIO content into an NSImage instance without writing the file to disk.

@daredoes
Copy link
Collaborator

Oh, I see. If you submit a Pull Request with the changes I'd be happy to review it.

@JokerQyou
Copy link
Author

Actually that's the problem: I cannot show the image.
First I tried your code in #89, and got this error:

2018-12-01 11:43:28.040 Python[42369:18111772] Traceback (most recent call last):
  File "/Users/joker/Works/rumps/rumps/rumps.py", line 1035, in callback_
    return _call_as_function_or_method(callback, self)
  File "/Users/joker/Works/rumps/rumps/rumps.py", line 384, in _call_as_function_or_method
    return method(event)
  File "simple.py", line 20, in sayhi
    rumps.show_image('/Users/joker/Downloads/256.png')
  File "/Users/joker/Works/rumps/rumps/rumps.py", line 212, in show_image
    return _nsimage_window_from_file(image)
  File "/Users/joker/Works/rumps/rumps/rumps.py", line 277, in _nsimage_window_from_file
    window = NSImageView.alloc().init(image)
TypeError: Need 0 arguments, got 1

I worked around by using this instead of NSImageView.alloc().init(image):

window = NSImageView.alloc().init()
window.setImage_(image)

This time I got no error, but the image did not show up either.

Now that I know how to converting raw bytes into an NSImage instance, it would be nice if I could be able to test it.

data = NSData.dataWithBytes_length_(raw_bytes, len(raw_bytes))
image = NSImage.alloc().initWithData_(data)

@axeII
Copy link

axeII commented Dec 1, 2018

/Users/joker

f4c4c416f43c8bd97b4a51f61d727829fdb4f175ab09763f3c589135116161f1

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

No branches or pull requests

3 participants