开发者

Embedded images in wxHaskell

I'm a Python programmer with experience in wxPython, and I'm learning Haskell and having a go at coding up a small GUI project in wxHaskell. One feature from wxPython that I have not yet figured out how to duplicate is PyEmbeddedImage - where images can be stored as strings inside Python m开发者_开发百科odules, and then accessed from wxPython. Does this functionality exist in wxHaskell, and if so, how do you do it?

Thanks!


You can try to use file-embed to embed file and then use imageCreateFromPixels to create image.

Use imageGetPixels to prepare file before embedding (e.g. create a wx app that will load image from resource directory and serialize to file)


I quite like Yuras suggestion to use the file-embed package, which automates the task of embedding data into a bytestring.

To see how to do this manually, check the Haskell wiki article on compiled constant data structures (e.g. to compile in large maps or other data structures).

The use of bytestring and the -XOverloadedStrings extension nicely avoids the need for magic unboxed values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜